[英]how to change the uinavigationbar background color without overriding drawRect:
[英]Change the background color of UINavigationBar
我想更改UINvaigationBar的背景顏色,並且使用了tintColor屬性,但它沒有更改顏色。 您可以在下面查看代碼。
在我的Appdelegate中,我創建一個UITabBarController
tabbar = [[UITabBarController alloc] init];
然后我創建一個UINavigationController並將我的UITableViewController附加到它
UINavigationController *myNavigation = [[UINavigationController alloc] initWithRootViewController:myViewController];
然后像這樣將UINavigationControllers附加到我的標簽欄
[tabbar setViewControllers:viewControllers]; //viewControllers is an array of UINavigationControllers
我試圖像這樣在myAppdelegate中設置屬性tintColor
[[myNavigation navigationBar] setTintColor:[UIColor redColor]];
但這沒有按預期工作,因此我在ViewController中嘗試了相同的操作
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController.navigationBar setTintColor:[UIColor blackColor]];
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
self.navigationItem.title = @"Test";
}
仍然沒有任何反應。 請查看下面的圖片,以查看導航欄現在的外觀。
感謝您的幫助。
干杯
作為一種變通辦法,您可以在色彩的位置使用圖像,請檢查以下代碼是否相同。
if ([myNavigation respondsToSelector:@selector(setBackgroundImage:forToolbarPosition:barMetrics:)]) {
[myNavigation setBackgroundImage:[UIImage imageNamed:BAR_IMAGE_NAME] forbarMetrics:UIBarMetricsDefault];
}else {
[myNavigation insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:BAR_IMAGE_NAME]] autorelease] atIndex:0];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.