为了账号安全,请及时绑定邮箱和手机立即绑定

iOS 7导航栏文本和箭头颜色

iOS 7导航栏文本和箭头颜色

繁星淼淼 2020-02-03 14:52:06
我想将导航栏的背景设置为黑色,并将其中的所有颜色设置为白色。因此,我使用了以下代码:[[UINavigationBar appearance] setTitleTextAttributes:     [NSDictionary dictionaryWithObjectsAndKeys:      [UIColor whiteColor],      NSForegroundColorAttributeName,      [UIColor whiteColor],      NSForegroundColorAttributeName,      [NSValue valueWithUIOffset:UIOffsetMake(0, -1)],      NSForegroundColorAttributeName,      [UIFont fontWithName:@"Arial-Bold" size:0.0],      NSFontAttributeName,      nil]];但是后退按钮的文字颜色,箭头和方向键仍为默认蓝色。如何更改下图所示的颜色?
查看完整描述

3 回答

?
一只名叫tom的猫

TA贡献1906条经验 获得超2个赞

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;


查看完整回答
反对 回复 2020-02-03
?
慕勒3428872

TA贡献1848条经验 获得超5个赞

这花了我大约半天时间才弄清楚,但这对我有用。在用于初始化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]];


查看完整回答
反对 回复 2020-02-03
?
MMMHUHU

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


查看完整回答
反对 回复 2020-02-03
  • 3 回答
  • 0 关注
  • 890 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信