[英]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.