Yevheniia Zelenska
Yevheniia Zelenska

Reputation: 367

Can UITextView be filled with text starting from bottom edge?

How to make a UITextView to be filled with text starting from bottom edge, if it has unchangeable height?

UPD: The text in UITextView should be shown on the in the bottom despite the UITextView's size.

Upvotes: 1

Views: 1254

Answers (3)

iPhoneDev
iPhoneDev

Reputation: 11

This worked for me:

Set self as the UITextViewDelegate.

-(void)resizeToContent
{
    if (self.alignBottomUp)
    {
        UIEdgeInsets inset = UIEdgeInsetsZero;
        CGFloat height = ceilf([self sizeThatFits:self.bounds.size].height);
        inset.top = self.bounds.size.height - height;
        self.textContainerInset = inset;
    }
}


-(void)setAlignBottomUp:(BOOL)value
{
    if (value != _alignBottomUp)
    {
        _alignBottomUp = value;
        [self resizeToContent];
    }
}

- (void)textViewDidChange:(UITextView *)textView
{
    if (self.alignBottomUp)
    {
        [self resizeToContent];
    }
}

See also: UITextView doesn't update its contentSize

Upvotes: 1

Gad
Gad

Reputation: 2877

If I understand you correctly you are trying to align your text to the bottom of the UITextView. As far as I know there is no built in way to do this so you'll have to write it by yourself. Take a look at the answer to this question which describes one possible way of doing this.

Upvotes: 0

foundry
foundry

Reputation: 31745

In your textView delegate:

    - (void)textViewDidChange:(UITextView *)textView {
        UIEdgeInsets inset = UIEdgeInsetsZero;
        inset.top = textView.bounds.size.height-textView.contentSize.height;
        textView.contentInset = inset;
    }

Upvotes: 1

Related Questions