views:

1050

answers:

3
+3  Q: 

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?

+4  A: 

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

Aviad Ben Dov
+5  A: 

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;
dmercredi
This is a much better answer than the one currently marked correct.
hatfinch
I say not really, this has a little more detail but Aviad has a cooler icon.
Kendall Helmstetter Gelner
A: 

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

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

David M.