3 回答
TA贡献1906条经验 获得超3个赞
UINavigationBar从iOS 7开始,某些属性的行为已更改。您可以在下面显示的图像中看到:
我想与您分享两个美丽的链接。有关更多详细信息,您可以通过以下链接:
iOS 7 UI过渡指南。
如何为iOS更新您的应用程序7。
苹果文档的barTintColor说:
除非您将半透明属性设置为NO,否则默认情况下此颜色为半透明。
样例代码:
self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
[self.navigationController.navigationBar
setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
self.navigationController.navigationBar.translucent = NO;
TA贡献1848条经验 获得超6个赞
这花了我大约半天时间才弄清楚,但这对我有用。在用于初始化navigationController的rootViewController中,将以下代码放入viewDidAppear方法中:
//set bar color
[self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:85.0/255.0 green:143.0/255.0 blue:220.0/255.0 alpha:1.0]];
//optional, i don't want my bar to be translucent
[self.navigationController.navigationBar setTranslucent:NO];
//set title and title color
[self.navigationItem setTitle:@"Title"];
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor]];
//set back button color
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor,nil] forState:UIControlStateNormal];
//set back button arrow color
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
TA贡献1834条经验 获得超8个赞
Swift3,iOS 10
要全局分配颜色,请在AppDelegate中didFinishLaunchingWithOptions:
let textAttributes = [NSForegroundColorAttributeName:UIColor.white]
UINavigationBar.appearance().titleTextAttributes = textAttributes
Swift 4,iOS 11
let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white]
UINavigationBar.appearance().titleTextAttributes = textAttributes
- 3 回答
- 0 关注
- 967 浏览
添加回答
举报