Search code examples
iosobjective-cios7sizetofit

Resizing UITextView - Height not adjusting


This should be so easy, but for some reason it's not working for me. I want to resize my text box and ideally have some padding at the bottom. For now I'll settle for resizing properly.

The setup

A single view on my storyboard

Interface

@property (weak, nonatomic) IBOutlet UITextView *messageTextBox;

Implementation

- (void)viewDidLoad
{
    [super viewDidLoad];
    _messageTextBox.text = _message.body;
    [_messageTextBox sizeToFit];  
}

I have tried several different solutions including changing the height of the frame and other user suggestions here...

This is using ios7 and xcode 5, but I don't see why there would be an issue with such a basic function.

To add to my confusion, I have logged the frame height and contentsize after sizeToFit. My results are:

2013-10-02 18:40:20.803 narg[21467:a0b] H of the frame: 618.000000
2013-10-02 18:40:20.804 narg[21467:a0b] W of the frame: 469.000000
2013-10-02 18:40:20.804 narg[21467:a0b] Reported H of contentSize property on object 42.000000

So the frame clearly knows the correct height, but on the display all the text is cutoff and the box doesn't adjust size.


Solution

  • Here was the answer to my issue. At some point I had checked off Autolayout on my view. This effectively locked the view and didn't allow me to adjust the frame size.

    If you are seeing a similar issue that the frame is not resizing try the following:

    • Go to interface builder and open the view
    • Click on the file inspector
    • Deselect auto-layout.

    This resolved my issue.