如何在UIFont
中获得标题的UINavigationController
?我试图这样读:
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Some text here";
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSLog(@"navigation bar title attributes = %@", self.navigationController.navigationBar.titleTextAttributes);
NSLog(@"title font = %@", [self.navigationController.navigationBar.titleTextAttributes objectForKey:UITextAttributeFont]);
}
输出令人失望。 titleTextAttributes
字典只包含一个键/值,而不是字体。
navigation bar title attributes = {
NSColor = "UIDeviceWhiteColorSpace 1 1";
}
title font = (null)
答案 0 :(得分:2)
你走在正确的轨道上。但请记住,如果没有为特定UINavigationBar
或UIAppearance
代理设置任何字体,则会使用默认字体。
要确定默认字体,如果找不到特定字体,请使用UIFont
类方法systemFontOfSize:
和systemFontSize
。
答案 1 :(得分:2)
您可以访问导航栏的子视图以获取可标题和获取字体
for (UIView *sv in self.navigationController.navigationBar.subviews)
{
if (sv.subviews.count > 0 && [sv.subviews[0] isKindOfClass:[UILabel class]])
{
UILabel *lbl = (UILabel *)sv.subviews[0];
NSLog(@"%@",lbl.font);
break;
}
}
控制台输出
<UICTFont: 0xd8a3e50> font-family: "Helvetica-Light"; font-weight: normal; font-style: normal; font-size: 16.00pt