【swift】 UILabelのfontにstyleを適用する方法
XcodeでのUILabelのフォントでstyleを指定できるのにコードではそれらしきものが見つからなくて調べた。メモ
参考ページ:
stackoverflow.com
// Weights used here are analogous to those used with UIFontDescriptor's UIFontWeightTrait. // See the UIFontWeight... constants in UIFontDescriptor.h for suggested values. // The caveat above about the use of ...systemFont... methods applies to these methods too. @available(iOS 8.2, *) public class func systemFontOfSize(fontSize: CGFloat, weight: CGFloat) -> UIFont
上記のメソッドを使うとできるみたい。
ios8.2以上対応みたいですね!
weightにて指定できるのは以下
UIFontWeightUltraLight UIFontWeightThin UIFontWeightLight UIFontWeightRegular UIFontWeightMedium UIFontWeightSemibold UIFontWeightBold UIFontWeightHeavy
実際の指定方法は↓
label.font = UIFont.systemFontOfSize(17.0, weight: UIFontWeightThin)
以上。