【发布时间】:2014-03-26 04:47:36
【问题描述】:
我正在尝试使用以下代码设置导航栏文本的样式,但无法使其正常工作。我之前在这里有代码,但 Xcode 一直告诉我它已被 iOS 7 弃用。关于如何让它工作的任何建议?
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.navigationController setNavigationBarHidden:NO];
//SET COLORS AND FONTS
UIColor* mainColor = [UIColor colorWithRed:28.0/255 green:158.0/255 blue:121.0/255 alpha:1.0f];
UIColor* darkColor = [UIColor colorWithRed:7.0/255 green:61.0/255 blue:48.0/255 alpha:1.0f];
NSString* fontName = @"Avenir-Book";
NSString* boldFontName = @"Avenir-Black";
//[self styleNavigationBarWithFontName:boldFontName];
self.title = @"Walk With Me";
UINavigationBar* navAppearance = [UINavigationBar appearance];
[navAppearance setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor redColor], NSForegroundColorAttributeName,
[UIFont fontWithName:boldFontName size:18.0f], NSFontAttributeName,
[NSValue valueWithCGSize:CGSizeMake(0.0, 0.0)], NSShadowAttributeName,
nil]];
}
【问题讨论】:
-
您使用了错误的键和值顺序,所以它不起作用。
-
试试这个:NSDictionary *textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor grayColor], UITextAttributeTextColor,[UIFont fontWithName:@"HelveticaNeue-UltraLight" size:20.0],UITextAttributeFont, nil]; [[UINavigationBar 外观] setTitleTextAttributes:textTitleOptions];
-
@DhavalBhadania:当我尝试这个时,我收到一个错误,说它们已被弃用......
-
@sharataka 请检查我的答案
-
@sharataka 它在我的应用程序中的 ios 7 中完美运行
标签: ios ios7 uinavigationbar