我使用 Xcode 5 创建一个主从项目。默认导航栏如下所示:
现在我创建一个新的 UIViewContrller 文件及其 xib 文件:
我在视图中添加了一个 NavigationBar,并将背景颜色设置为绿色,但状态栏区域在导航栏中。如何将其配置为 MasterController 导航栏显示?
我使用 Xcode 5 创建一个主从项目。默认导航栏如下所示:
现在我创建一个新的 UIViewContrller 文件及其 xib 文件:
我在视图中添加了一个 NavigationBar,并将背景颜色设置为绿色,但状态栏区域在导航栏中。如何将其配置为 MasterController 导航栏显示?
你有2个选择。
要么创建一个 UINavigationViewController,然后设置你的 ViewController 有那个 UINavigationViewController 的 rootViewController(它会自动创建一个导航栏,上面有适当的状态栏颜色),
或者您可以保留您的导航栏,将其 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];
}