2015-04-03 40 views
0

如何使用不同的系統字體爲行//pointsLabel.font = FontHUD,沒有自定義字體,但不同的字體,可以在系統什麼是迅速的一個基本的字體,我可以使用的UILabel

//"points" label 
    var pointsLabel = UILabel(frame: CGRectMake(ScreenWidth-340, 30, 140, 70)) 
    pointsLabel.backgroundColor = UIColor.clearColor() 
    //pointsLabel.font = FontHUD 
    pointsLabel.text = " Points:" 
    self.addSubview(pointsLabel) 

回答

1

你可以使用UIFont.preferredFontForTextStyle(style: String)並通過以下任何作爲的風格:

UIFontTextStyleHeadline 
UIFontTextStyleSubheadline 
UIFontTextStyleBody 
UIFontTextStyleFootnote 
UIFontTextStyleCaption1 
UIFontTextStyleCaption2 

對位旁註的 - 使用preferredFontForTextStyle的好處是,你可以用它來使你的應用程序支持動態類型,因爲大小o f返回的字體因用戶的首選文字大小而異(在「設置」應用程序的「顯示器&亮度 - >文字大小」下設置)。要完全支持動態類型,您應該使用NSNotifcationCenter並觀察UIContentSizeCategoryDidChangeNotification來傾聽首選字體大小的更改,然後適當地更新標籤/文字瀏覽。

相關問題