宣告並初始化 UIFont

你可以按如下方式宣告 UIFont

var font: UIFont!

UIFont 有更多的 init() 方法:

  • UIFont.init(descriptor: UIFontDescriptor, size: CGFloat)
  • UIFont.init(name: String, size: CGFloat)

因此,你可以像這樣初始化 UIFont

let font = UIFont(name: "Helvetica Neue", size: 15)

預設字型為 System,大小為 17