如何在不改变大小的情况下更改字体?

时间:2012-11-07 04:35:07

标签: objective-c xcode4.5

[[UINavigationBar appearance] setTitleTextAttributes:
 @{UITextAttributeTextColor: navTextColor,
 UITextAttributeTextShadowColor: navTextColor,
 UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
 UITextAttributeFont: [UIFont fontWithName:@"HelveticaNeue-Bold" size:12]}];

该代码将UINavigationBar的字体更改为HelveticaNeue-Bold并将大小设置为12.

如果我不想将大小设置为12怎么办。我只想将字体设为HelveticaNeue

我该怎么办?

1 个答案:

答案 0 :(得分:1)

您可以使用titleTextAttributes来获取字体大小,这是刚刚添加到iOS 5的UINavigationBar上的NSDictionary。然后只需调用[navibar.titleTextAttributes objectForKey:UITextAttributeFont];即可获得标题的UIFont。