Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS - remove ALL padding from UITextView

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"

enter image description here

like image 828
mattyd Avatar asked Apr 05 '13 00:04

mattyd


1 Answers

Although it is iOS 7 only, an extremely clean solution is to set the textView's textContainerInsets as such:

[textView setTextContainerInset:UIEdgeInsetsZero]; textView.textContainer.lineFragmentPadding = 0; // to remove left padding 

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.

like image 55
dbart Avatar answered Sep 24 '22 02:09

dbart