SAH*_*AHM 5 fonts ios ios11 large-title
我知道如何设置颜色并更改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);
Run Code Online (Sandbox Code Playgroud)
rma*_*ddy 14
获取大标题字体的正确解决方案如下:
Objective-C的:
UIFont *font = [UIFont preferredFontForTextStyle: UIFontTextStyleLargeTitle];
NSLog("%@", font);
Run Code Online (Sandbox Code Playgroud)
迅速:
let font = UIFont.preferredFont(forTextStyle: .largeTitle)
print(font)
Run Code Online (Sandbox Code Playgroud)
即使用户在"设置"应用中应用了各种辅助功能和字体大小更改,也会提供正确的值.
以上将默认打印出以下内容(在操场上):
<UICTFont:0x7fa865c05390> font-family:".SFIIDisplay"; font-weight:normal; font-style:normal; font-size:34.00pt
请注意,.largeTitle必须仅使用iOS 11调用上述代码中的使用.如果您的应用支持iOS 10或更早版本,则必须正确使用该代码@available.
Tom*_*ren 10
在 iOS 13 上,这正是导航栏中大标题使用的字体。我逐个像素地比较了屏幕截图,结果完全匹配!
UIFont.systemFont(ofSize: 34, weight: .bold)
Run Code Online (Sandbox Code Playgroud)