更改导航栏的文本属性

时间:2013-06-07 08:51:56

标签: objective-c

我想更改导航栏的外观,到目前为止我能够更改导航栏的背景图像,还可以更改颜色。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:     (NSDictionary *)launchOptions {

//set the bg image of all nav bars
UIImage *navBackgroundImage = [UIImage imageNamed:@"navigationBackground.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];

return YES;

//customizing the title text of the nav bars
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
                                                       [UIColor colorWithRed:255.0/255.0 green:250.0/250.0 blue:240.0/240.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:@"Heiti TC" size:21.0], UITextAttributeFont, nil]];

}

这是我用来改变导航栏bg图像和颜色的代码。如果你查看第二个UINavigationBar外观语句,我尝试用
设置导航栏的字体     [UIFont fontWithName:@"Heiti TC" size:21.0]

但它不会改变字体。顺便说一句,我在xcode 4.6.2上运行iphone 6.1模拟器。我确定字体名称是“Heiti TC”。

3 个答案:

答案 0 :(得分:1)

也许它不起作用,因为你

return YES;

在更改字体之前?

答案 1 :(得分:0)

一切看起来都很正确。我已经使用类似的代码来实现预期。您是否尝试使用字体 Heiti TC Light Heiti TC Medium

答案 2 :(得分:0)

为方法fontWithName提供的名称与显示的字体的系列名称不同。

尝试使用“STHeitiTC-Light”或“STHeitiTC-Medium”。

[UIFont fontWithName:@"STHeitiTC-Medium" size:21.0]

然后把

  

返回YES

在didFinishLaunchingWithOptions的末尾。

PS:这里的答案非常有助于找到要使用的字体名称:Cant find custom font - iOS

相关问题