3

I have a UITextView but text in it is align to the bottom but I want there will be a margin from the bottom like this:

----------------

some text

----------------

If I have a UITextField I can use editingRectForBounds:. But what about UITextView how can I achieve this functionality with it? ANY solution will be appreciated. And ,please, don't advice me to use UITextField instead! I need UITextView. Thanks in advance.

MainstreamDeveloper00
  • 8,436
  • 15
  • 56
  • 102
  • 1
    Have You tried `yourTxtView.contentInset` property ? – Buntylm Jul 23 '13 at 12:07
  • 1
    This question has now a better and more popular alternative here: https://stackoverflow.com/questions/19065693/how-to-set-content-inset-for-uitextview-in-ios – Cœur Jun 09 '17 at 04:48

2 Answers2

23

For a UITextView in iOS 7, use this:

textView.textContainerInset = UIEdgeInsetsMake(10, 10, 10, 10);

Alex Zavatone
  • 4,106
  • 36
  • 54
6

For iOS 6, try this:

TxtView =[[UITextView alloc] initWithFrame:CGRectMake(x, y, 250, 70)];
    TxtView.font = [UIFont systemFontOfSize:15];
    TxtView.autocorrectionType = UITextAutocorrectionTypeNo;
    TxtView.clipsToBounds = YES;
    TxtView.scrollEnabled=YES;
    TxtView.editable=YES;
    TxtView.contentSize=TxtView.frame.size;
    TxtView.returnKeyType = UIReturnKeyDone;
    TxtView.contentInset    = UIEdgeInsetsMake(-4,0,-4,0);  
    TxtView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    TxtView.layer.cornerRadius = 5;
    TxtView.clipsToBounds = YES;

Here, Inset is where you can give padding like values in textview. textview height is autoresizing so it will be changed according to text.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Armaan Stranger
  • 3,140
  • 1
  • 14
  • 24