I'm trying to set the height of a UITextView from a UIViewController's viewWillAppear event, here's the code:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
textView.text = blah blah...
textView.frame = CGRectMake(textView.frame.origin.x, textView.frame.origin.y,
textView.frame.size.width, textView.frame.size.height-20);
}
However, it seems to ignore my sizing, it's as though after this event is called, the textview is resized by something else.
What am i doing wrong? Is there some good way to do this?
Thanks
-edit-
Got it working by putting the code in my viewDidAppear instead of the viewWillAppear. So it works now.
Although i'm puzzled why i need to do this (remove 20 pixels from the bottom) - i mean shouldn't it resize to fill auto开发者_如何转开发matically? Why is it resizing to 20px too long? There's a tab bar at the bottom and a nav bar up the top. Is that confusing it?
Simple but obvious question, does the text change, in other words, is the outlet hooked up in IB?
JUSTA TIP: Look at using the helper functions for CGRect such as:
textView.frame = CGRectInset(textView.frame, 0, 20);
In an app with just this code and a single TextView the resizing occurs as expected. So..it's definitely something else in your app.
Are you maybe referencing the contentsize property or something else in your viewDidAppear?
Got it working by putting the code in my viewDidAppear instead of the viewWillAppear. So it works now.
Although i'm puzzled why i need to do this (remove 20 pixels from the bottom) - i mean shouldn't it resize to fill automatically? Why is it resizing to 20px too long? There's a tab bar at the bottom and a nav bar up the top.
精彩评论