我知道如何设置颜色并更改iOS 11中大标题的字体,但我很难找到大标题的默认字体和字体大小。我想在应用程序的其他地方重现该字体。我尝试了以下但是它们没有给出字体或字体大小的结果。不确定我应该在哪里寻找这个。
NSLog(@"self.navigationController.navigationBar.largeTitleTextAttributes:%@",self.navigationController.navigationBar.largeTitleTextAttributes);
NSDictionary *dict = self.navigationController.navigationBar.largeTitleTextAttributes;
UIFont *font = [dict objectForKey:@"NSFontAttributeName"];
NSLog(@"font is.. %@, %@, %@",font,font.fontName,font.fontDescriptor);
获取大标题字体的正确解决方案如下:
Objective-C的:
UIFont *font = [UIFont preferredFontForTextStyle: UIFontTextStyleLargeTitle];
NSLog("%@", font);
迅速:
let font = UIFont.preferredFont(forTextStyle: .largeTitle)
print(font)
即使用户在“设置”应用中应用了各种辅助功能和字体大小更改,也会提供正确的值。
以上将默认打印出以下内容(在操场上):
<UICTFont:0x7fa865c05390> font-family:“。SFIIDisplay”; font-weight:normal; font-style:normal; font-size:34.00pt
请注意,必须仅在iOS 11中调用上面代码中的.largeTitle
。如果您的应用程序支持iOS 10或更早版本,则必须正确使用@available
来包装该代码。
iOS12大型标题系统Bold 34(旧金山)
[UIFont boldSystemFontOfSize:34]
iOS9 - iOS12系统Semibold 17(旧金山)
[UIFont systemFontOfSize:17 weight:UIFontWeightSemibold]
iOS8系统Semibold 17(Helvetica New)
[UIFont systemFontOfSize:17 weight:UIFontWeightSemibold]
iOS7系统Bold 17(Helvetica New)
[UIFont boldSystemFontOfSize:17];
我实际上通过尝试不同的字体和大小找到答案。现在,免责声明,这可能会随着可访问性/动态字体大小而改变。但我发现的字体和大小是
[UIFont systemFontOfSize:32 weight:UIFontWeightBold]
我仍然想找到一种方法来以编程方式获得这个并等待接受答案,希望有人可能知道如何做到这一点。与此同时,希望这对某人有所帮助。
我非常肯定它至少是iOS 11+
斯威夫特5:
UIFont.init(name: ".SFUIDisplay-Bold", size: 32)