How to center something vertically on screen when using UINavigationController on iOS?
I've got a UIView
defined in IB within a UIViewController
, and I have placed completely centered (vertical and horizontal) an activity spinner. 开发者_开发技巧 This all looks great, except in practice I use it by pushing the UIViewController on to a UINavigationController
- hence, it displays "pushed down" my screen 50 pixels or whatever, so my spinner is no longer centered.
How do you address this? I want the same code to work on all iOS devices. I don't mind adding it programatically - maybe I need to? But I don't know how to make use of screen size vs view size vs nav view size and then end up with "local" coordinate frame for the spinner.
Try setting its center
property to the same value of the hosting view's one.
So in viewDidLoad
, do something like :
myIndicator.center = self.view.center;
This should make it, but you can also calculate it with few instructions.
精彩评论