我试图动态提供字体大小,样式,字体和粗细,以及屏幕分辨率。
我尝试过:
title_home.font = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.title1)
subtitle_home.font = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.title2)
subtitle1_home.font = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.title2)
subtitle2_home.font = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.title2)
但是正在以正常的常规尺寸显示文本。我需要标题为粗体,并且要有一定的大小,并且标题应该根据屏幕的分辨率进行更改。
答案 0 :(得分:0)
您可以根据描述符获得粗体/斜体/等首选字体,如下所示:
let descriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .headline)
.addingAttributes([.traits : [UIFontDescriptor.TraitKey.weight: UIFont.Weight.semibold]])
let semiboldFont = UIFont(descriptor: descriptor, size: 0)
print(semiboldFont)
//<UICTFont: 0x7fe03300cc30> font-family: ".SFUIText-Semibold"; font-weight: bold; font-style: normal; font-size: 17.00pt
希望有帮助