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来倾听首选字体大小的更改,然后适当地更新标签/文字浏览。

相关问题