使导航栏在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中,状态栏顶部会有一个空白区域,我希望导航栏也能填满这个区域
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
的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: