views:

424

answers:

1

Hello all,

I'm an iPhone dev newbie, and I'm running into a problem figuring out how much of an UIView I'm able to use when the UIViews's controller is part of an UITabController. I'm initializing the window as

window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

and the view as

myView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

The window is coming back as 320x480, and the view as 320x460 (the 20 pixel difference is, I assume, the status bar on top).

However, the view is part of a UITabController, and I don't know how to calculate the amount of space that is availabe when taking that tab bar into account. Any ideas?

+3  A: 

I assume you are creating a view programmatically and are trying to dynamically lay it out within the tab controller. Use the UIViewAutoresizing and trust on the OS to do it for you.

I was having similar trouble until I took the time to understand how to use the Flexible attributes to lock elements in certain positions. When you use the tab controller to switch the selected view, the OS will resize the view to fit automatically.

UIViewAutoresizingFlexibleTopMargin - Locks the location of an object with regards to the bottom.
UIViewAutoresizingFlexibleBottomMargin - Locks with regards to the top.
UIViewAutoresizingFlexibleWidth - Keeps the object the same distance from the left and right edges.
UIViewAutoresizingFlexibleHeight - Keeps the object the same distance from the top and bottom edges.

The top and bottom seem backwards at first until you realize that defining the margin that is allowed to change.

To configure this programmatically, you need to set the autoresizingMask of the view:

[myView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin];
toast
Thanks, that's exactly what I was looking for. I appreciate it.
John Biesnecker