Jichao
Jichao

Reputation: 41805

How to get the top bar height of ios application window?

I need to layout a segment control right under the top bar height of a uiwindow such as this.

enter image description here

I have searched the UIWindow reference but found nothing.

Upvotes: 0

Views: 371

Answers (2)

jcaron
jcaron

Reputation: 17710

The best option is to use the top layout guide (topLayoutGuide). This will tell you where to place your subviews, based on the presence and size of the status bar, navigation bar, whether the view extends below them, etc.

Ideally, you should use auto-layout. Then just add a constraint from the view's top to the top layout guide (in Interface Builder, control-drag from the view to the superview and select "Vertical Spacing to Top Layout Guide").

Don't forget the status bar can change size (during a call and other similar circumstances). With auto-layout, this will be taken care of for you automatically.

Upvotes: 1

Jonathan
Jonathan

Reputation: 2383

That's known as the status bar. Off the top of my head I think you can find the frame for it using

[UIApplication sharedApplication].statusbarFrame

Upvotes: 1

Related Questions