通过代码设置系统自带字体样式

当我们通过Storyboard布局UILabel 时,可以清楚的调整字体的粗细选项,如图:

通过代码设置系统自带字体样式_第1张图片

但是代码并未明确有这么多的选项,那怎么办呢?

label.font = UIFont.systemFont(ofSize: 17, weight: UIFontWeightMedium)

@available(iOS 8.2, *)
public let UIFontWeightUltraLight: CGFloat
@available(iOS 8.2, *)
public let UIFontWeightThin: CGFloat
@available(iOS 8.2, *)
public let UIFontWeightLight: CGFloat
@available(iOS 8.2, *)
public let UIFontWeightRegular: CGFloat
@available(iOS 8.2, *)
public let UIFontWeightMedium: CGFloat
@available(iOS 8.2, *)
public let UIFontWeightSemibold: CGFloat
@available(iOS 8.2, *)
public let UIFontWeightBold: CGFloat
@available(iOS 8.2, *)
public let UIFontWeightHeavy: CGFloat
@available(iOS 8.2, *)
public let UIFontWeightBlack: CGFloat

你可能感兴趣的:(通过代码设置系统自带字体样式)