Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing UIViews

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?

like image 729
mire Avatar asked Aug 17 '09 19:08

mire


3 Answers

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..

like image 184
Aviad Ben Dov Avatar answered Nov 10 '22 17:11

Aviad Ben Dov


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;
like image 30
dmercredi Avatar answered Nov 10 '22 16:11

dmercredi


Use this UIView+position category to get convenient property access to the frame's members:

http://bynomial.com/blog/?p=24

like image 3
David M. Avatar answered Nov 10 '22 18:11

David M.