如何在UINavigationBar中设置自定义字体? [英] How can I set custom font in UINavigationBar?
问题描述
如何在UINavigationBar中设置自定义字体?我需要tahoma字体。
How can I set custom font in UINavigationBar ? I need the tahoma font.
- (void)viewDidLoad{
self.title =@"My text";
}
推荐答案
完全有可能,如果有点棘手的话。一旦找到了所需的字体(iOS中附带的替代品之一,或者您获得了正确许可的TTF文件),只需创建一个包含大小,格式,字体等的UILabel,然后添加它到该栏的导航项目(或者,如果您在视图控制器中执行此操作,请将该控制器的.navigationItem.titleView设置为您的标签)。
Totally possible, if a little tricky to do. Once you've found the font you need (either one of the alternatives already shipped with iOS, or a TTF file that you've got the correct licensing for), just create a UILabel with the size, formatting, font etc and then add it to the navigation items for that bar (or, if you're doing this in a view controller, set the .navigationItem.titleView of that controller to your label).
例如,我在UINavigationController中有一个视图控制器。要将顶部的标签更改为自定义字体,我只需执行以下操作:
For example, I have a view controller inside a UINavigationController. To change the label in the top to a custom font, I simply do:
//...I have already setup a UILabel called navLabel that has the same style as a
// default navigation bar title, but I've changed the .font property to my custom font
self.navigationItem.titleView = navLabel;
[navLabel release];
这篇关于如何在UINavigationBar中设置自定义字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!