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

查看:111
本文介绍了使导航栏在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

谢谢!

推荐答案

你想设置 barPosition UINavigationBar

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

让ViewController符合协议 UINavigationBarDelegate 并实现positionBar:metod。 (你真正需要的协议是 UIBarPositioningDelegate 但是 UINavigationBarDelegate 确实扩展了它。)

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 的I​​dentity 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天全站免登陆