这个崩溃的应用程序:iOS - 使用外观全局更改导航栏标题颜色?
[[UINavigationBar appearance] setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
有没有办法做到这一点使用的外观?
这个崩溃的应用程序:iOS - 使用外观全局更改导航栏标题颜色?
[[UINavigationBar appearance] setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
有没有办法做到这一点使用的外观?
这工作:
NSDictionary *textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor darkGrayColor], UITextAttributeTextColor, [UIColor whiteColor], UITextAttributeTextShadowColor, nil];
[[UINavigationBar appearance] setTitleTextAttributes:textTitleOptions];
那崩溃之前UINavigationBar的应用程序没有标题或状态......这些都是UIButton的方法
你需要
[[UINavigationBar appearance] setTintColor:[UIColor darkGrayColor]];
不,这没有用。我认为这是为了自己的色彩。我们已经使用setBackgroundImage:方法来更改导航栏背景,所以现在我需要将文本颜色从白色改为深灰色,以便它清晰易读。 – RyJ
对不起,你不知道你试图设置navBar文本颜色。以为你只是想改变它的颜色。 –
的@ RyJ的回答非常好,为我工作。想我会解囊,有在雷Wenderlich的网站,标题上这是一个很好的教程(请原谅这个双关语):
User Interface Customization in iOS 6
请参阅部分定制UINavigationBar的
下面是代码片段导航栏标题,在全球范围内改变:
// Customize the title text for *all* UINavigationBars
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
UITextAttributeTextColor,
[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
UITextAttributeTextShadowOffset,
[UIFont fontWithName:@"Arial-Bold" size:0.0],
UITextAttributeFont,
nil]];
一个其他次要的一点是,它似乎有标题栏默认的影子,所以要摆脱它,你不能只删除该属性。相反,您必须设置阴影偏移量:
UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetMake(0, 0)]
我使用以下代码更改标题栏的颜色。
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor blackColor];
shadow.shadowOffset = CGSizeMake(1, 0);
NSDictionary *titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],
NSShadowAttributeName:shadow};
[[UINavigationBar appearance] setTitleTextAttributes:titleTextAttributes];
下面是如何做到这一点在斯威夫特的例子:
UINavigationBar.appearance().titleTextAttributes =
[NSFontAttributeName:UIFont(name:"Exo2-Bold", size: 18) as! AnyObject,
NSForegroundColorAttributeName:UIColor.whiteColor()]
利用现代语法和实际运行的代码,这是怎么全局风格的UINavigationBar
标题文字:
NSShadow *navigationBarTitleShadow = [[NSShadow alloc] init];
navigationBarTitleShadow.shadowColor = [UIColor colorWithWhite:0.5
alpha:0.5];
navigationBarTitleShadow.shadowOffset = CGSizeMake(2.0, 2.0);
[[UINavigationBar appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor blackColor],
NSFontAttributeName : [UIFont fontWithName:@"Arial-BoldMT"
size:30.0],
NSShadowAttributeName : navigationBarTitleShadow }];
注意:NSShadow
的shadowBlurRadius
财产不受尊重。
注:阴影是如此的iOS 6.永远不要使用它们。
你应该接受你自己的答案。 –
非常有帮助..谢谢 –
工作得很好。如果您还需要设置主题活动UINavigationBar的,加入这一行: '[yourViewController.navigationController.navigationBar setTitleTextAttributes:textTitleOptions]' –