UITextView bottom alignment

I was wondering how to set a UITextView so that the text inside aligns to the bottom? For example, if you start typing, will you always enter the bottom line?

+5
source share
3 answers

I do not believe that there is a built-in way to vertically align text in UITextView, but you should be able to use a contentOffsetclass property UITextViewto accomplish this. See this blog post for more details:

http://imagineric.ericd.net/2011/03/10/ios-vertical-aligning-text-in-a-uitextview/

+13
source

Using autostart worked for me:

1) Place yours UITextViewso that the height is large enough for one line of text, and the bottom is attached to the bottom of the screen (or something under the text view).

2) Save the link in your view view controller NSLayoutConstraintfor the height of the text view.

3) Set your view controller as UITextViewDelegate

4) adjust the height of the text view when entering text and create a layout. For instance:

- (void)textViewDidChange:(UITextView *)textView;
{
    self.textViewHeightConstraint.constant = textView.contentSize.height;
    [self.textView layoutIfNeeded];
}
0
source

All Articles