使导航栏在 xCode 5/iOS7 中的状态栏后面伸展 [英] Make Navigation Bar stretch behind status bar in xCode 5 / iOS7

查看:15
本文介绍了使导航栏在 xCode 5/iOS7 中的状态栏后面伸展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照以下教程将我的导航栏向下移动,这样它就不会被 xcode 5/ios7 中的状态栏覆盖:

I have followed the following tutorial to move my navigation bar down so it is not covered by the status bar in xcode 5/ios7:

状态栏和导航栏问题IOS7

但是现在在 iOS7 中状态栏的顶部有一个空白区域,我希望导航栏也填充这个区域

But now in iOS7 there is a blank space at the top where the status bar would be and I would like the navigation bar to fill this area too

例如,Facebook/twittter/Instagram iOS7 应用程序在状态栏后面也有导航栏背景.我如何实现这一目标?

For instance, Facebook/twittter/Instagram iOS7 apps have the navigation bar background behind the status bar too. How do I achieve this?

对不起,如果我不清楚但真的很想解决这个问题

Sorry if I'm not being clear but really eager to get this sorted

谢谢!

推荐答案

您确实想设置 UINavigationBarbarPosition.

You do want to set the barPosition of the UINavigationBar.

您可以在代码中执行此操作:

让你的 ViewController 符合协议 UINavigationBarDelegate 并实现 positionBar: 方法.(您真正需要的协议是 UIBarPositioningDelegateUINavigationBarDelegate 确实扩展了它.)

Let your ViewController conform to protocol UINavigationBarDelegate and implement positionBar: metod. (The protocol that you really need is UIBarPositioningDelegate but UINavigationBarDelegate does extend it.)

@interface SampleViewController () <UINavigationBarDelegate>
@property (weak, nonatomic) IBOutlet UINavigationBar *navigationBar;
@end

@implementation SampleViewController

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

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

或在情节提要中:

UINavigationBar的Identity Inspector中,添加一个用户定义的运行时属性,KeyPath = barPosition,Type = Number,Value = 3:

In the Identity Inspector of UINavigationBar, add a User Defined runtime Attribute with KeyPath = barPosition, Type = Number, and Value = 3:

这篇关于使导航栏在 xCode 5/iOS7 中的状态栏后面伸展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆