If I need to resize or reposition a UIView, is there a better way to do it than the following?
view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height - 100);
Or in other words, is there a way to just say view.frame.size.height -= 100 through a non-readonly property?
If you want the -=100
effect, just do:
CGRect frame = view.frame;
frame.size.height -= 100;
view.frame = frame;
Then you can be certain you're changing exactly what you want to change, too..
Other than that, I don't think there's a way..
There isn't a property to directly manipulate the height.
Note that every time you call view.frame it calls the method, so your code is equivilent to:
view.frame = CGRectMake([view frame].origin.x, [view frame].origin.y, [view frame].size.width, [view frame].size.height - 100);
Consider instead adjusting the frame in a separate variable:
CGRect frame = view.frame;
frame.size.height -= 100;
view.frame = frame;
Use this UIView+position
category to get convenient property access to the frame's members:
http://bynomial.com/blog/?p=24
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With