2

我使用 Xcode 5 创建一个主从项目。默认导航栏如下所示:

在此处输入图像描述

现在我创建一个新的 UIViewContrller 文件及其 xib 文件:

在此处输入图像描述

我在视图中添加了一个 NavigationBar,并将背景颜色设置为绿色,但状态栏区域在导航栏中。如何将其配置为 MasterController 导航栏显示?

在此处输入图像描述

4

1 回答 1

5

你有2个选择。

  1. 要么创建一个 UINavigationViewController,然后设置你的 ViewController 有那个 UINavigationViewController 的 rootViewController(它会自动创建一个导航栏,上面有适当的状态栏颜色),

  2. 或者您可以保留您的导航栏,将其 Y 原点设置为 20,然后执行以下操作:

在 .h 文件中:

@interface XYZViewController : UIViewController <UIBarPositioningDelegate>

在 .m 文件中:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationBar.delegate = self;
}

- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar { 
    return UIBarPositionTopAttached; 
}

编辑:如何在手机横向模式下调整栏的大小:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [self.navigationBar sizeToFit];
}
于 2014-07-26T06:29:31.723 回答