There are many great examples on SO to remove the left padding of a UITextView.
How to lose margin/padding in UITextView?
However, I need to remove the right padding too.
I have tried...
[tv setContentInset: UIEdgeInsetsMake(-4,-8,-8,-X)];//where X is any integer
and just about every other permutation of the last two values to remove the padding and nothing seems to work. Have also tried
[tv sizeToFit];
[tv setTextAlignment:[NSTextAlignmentRight]];
The following Text in the Textview says "00"
My problem is solved this way
for more see http://foobarpig.com/iphone/get-rid-of-uitextview-padding.html
Swift 4 version for the OA
Please try sub-classing the UITextView and overriding the following method:
Apparently; you can tweak the margin-left, margin-top & whatever you want ;)
To completely remove all padding, the
lineFragmentPadding
must be taken into account.The
lineFragmentPadding
default value is 5, and is at the beginning and end of fragment rectangle.Some answers suggested setting
lineFragmentPadding
to 0. However, as per discussed in the doc, it is not designed to express text margins. So do not set it to 0.Although it is iOS 7 only, an extremely clean solution is to set the textView's textContainerInsets as such:
This will effectively remove all padding (insets) around the text inside the text view. If your deployment target is iOS 7+ then this is the best solution thus far.