![](/img/trans.png)
[英]How to remove UINavigationController / UINavigationBar background in objective-c?
[英]How to set the background of UINavigationBar in Objective-C ?
我想改變UINavigationBar
的background
。
我已經將圖像放到Images.xcassets
,而xib
文件是TableView
我寫了[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"bar-background.png"] forBarMetrics:UIBarMetricsDefault];
在viewDidLoad
中如下所示。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UIView* bview = [[UIView alloc] init];
bview.backgroundColor = [UIColor groupTableViewBackgroundColor];
//self.title = NSLocalizedString(@"WiFi Camera Viewer", nil) ;
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"bar-background.png"] forBarMetrics:UIBarMetricsDefault];
}
但UINavigationBar
沒有顯示如下圖像
如何在Objective-C中設置UINavigationBar的背景?
我錯過了什么嗎? 提前致謝。
您使用的代碼是舊的,從iOS 7開始,您可以使用下面的代碼
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"YourImage"] forBarMetrics:UIBarMetricsDefault];
如果您提供44px高度的圖像,它將僅覆蓋導航欄而沒有狀態欄,如果您提供66px高度,它將覆蓋它們兩者
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.