Search code examples
objective-cuinavigationcontrolleruitabbarxcode4.5

Is there a function to know the useableSize of a view?


It must take into account:

statusBar (which can be 40 points if you have hot spot) TabBar NavigationBar.

Basically at viewDidLoad I see that my view has a size of 320*480.

I wonder where did iOS decide that as the screen size of my screen. I use UIStoryBoard.

So, on viewDidLoad, I intended to resize that.

I am not even sure if this is the right approach.

Note: the issue I am facing doesn't seem to happen if I do not use storyBoard.

At viewDidLoad, when I use XIB, the content of self.view is correct, namely 416, instead of 480, due to UInavigationController and UITabBar


Solution

  • Try overriding the UIViewController viewWillLayoutSubviews method. The view's frame will be set by then.

    In the viewWillLayoutSubviews method, the view controller's main view is the size you need to know. It has been adjusted for status bars and nav bars and tools bars and tab bars. It also takes into account orientation. There is no single method where you can ask what the size will be. Besides, there is no need to ask such a question. Create all the subviews you want in viewDidLoad. But lay them out based on the view's size in viewWillLayoutSubviews.