1

I'm trying to change the height of a UITextView dynamically:

... UITextView* textView; ...

CGRect textViewNewFrame = CGRectMake(textView.frame.origin.x, textView.frame.origin.y, textView.frame.size.width, 130);
textView.frame = textViewNewFrame;

In IB, I have a UIButton top-aligned with my UITextView. The UIButton is 130px high; the UITextView is, say, 150px high.

If I run the code above, the UITextView ends up 44px too short. I have to change my CGRectMake line to end,

..., 130 + 44);

However, if in IB I 'hard-code' the height of the UITextView to 130px, the UIButton and UITextView are rendered both top- and bottom-aligned (they are both the same height).

So when changing the UITextView's frame's height dynamically I have to add 44, but not when 'statically' setting its height via IB.

Oddly, UILabel doesn't misbehave like this (I don't have to add 44px when dynamically resizing).

I know that 44 is a magic number in IB (the height of the nav bar etc) but why do I need to add it? Am I missing something/doing something wrong, or is this just an anomaly? I'm concerned that this must be such a common operation and yet I can't find anyone else asking the same question and coming to the same conclusion.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.