我正在尝试使用下面的代码设置导航栏文本的样式,但我无法使其工作。我之前有代码,但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]];
}
答案 0 :(得分:0)
以下是导航栏标题{ - 1}}的示例代码段 -
altering the font style
将图片用作导航栏标题
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
test.shadowOffset = CGSizeMake(0, 1);
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,
shadow, NSShadowAttributeName,
[UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil]];
答案 1 :(得分:0)
NSDictionary *titleTextAttributes=@{
NSForegroundColorAttributeName: [UIColor redColor],
NSFontAttributeName: [UIFont systemFontOfSize:17.0],};
UINavigationController * objView=(UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
objView.navigationBar.titleTextAttributes = titleTextAttributes;