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.

2
  • 1
    Have You tried yourTxtView.contentInset property ? Commented Jul 23, 2013 at 12:07
  • 1
    This question has now a better and more popular alternative here: stackoverflow.com/questions/19065693/… Commented Jun 9, 2017 at 4:48

2 Answers 2

24

For a UITextView in iOS 7, use this:

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

Sign up to request clarification or add additional context in comments.

1 Comment

This was the answer I went with. Seems the best solution for anything iOS7 and above.
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.

1 Comment

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.