[英]System font disappear on UIButton attributed title
当前的iOS系统字体为“旧金山”
您可以通过以下方式使用它:
UIFont.systemFont(ofSize: CGFloat, weight: UIFontWeight)
您也可以通过此页面上的链接下载字体: https : //developer.apple.com/ios/human-interface-guidelines/visual-design/typography/
没有情节提要,有一种更简单的方法来执行此操作。
签出此示例代码:
class VC: UIViewController{
@IBOutlet weak var button: UIButton! //button outlet
override func viewDidLoad() {
super.viewDidLoad()
// Initialization code
///here we are defining the attributes for the button title...
let textAttribute: [NSAttributedStringKey : Any] = [.foregroundColor: UIColor.blue, .font: UIFont.systemFont(ofSize: 14)]
self.button.setAttributedTitle(NSAttributedString(string: "Button", attributes: textAttribute), for: .selected)
}
}
从情节提要中,将属性文本更改回系统字体可能会令人沮丧。
好吧,如果属性文本足够简单,我可以建议这样做:
如果属性字符串很复杂,则可能需要仔细进行以下操作:
找到有罪的字体,例如:
<font key="NSFont" size="17" name="ComicSansMS"/>
用元字体替换,例如:
<font key="NSFont" metaFont="system" size="17"/>
返回标准编辑器
请注意,我很少使用情节提要中的属性字符串,因为它不支持翻译。 因此,通常,您将使用带有lorem ipsum的情节提要,并从代码中设置适当的NSAttributedString。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.