How to convert CGFontRef to UIFont?

后端 未结 6 1565
礼貌的吻别
礼貌的吻别 2020-12-03 03:57

I want to use a custom font for a UILabel. The custom font is loaded by from a file:

NSString *fontPath = ... ; // a TTF file in iPhone Document         


        
6条回答
  •  情歌与酒
    2020-12-03 04:07

    Updated for Swift 4 to get PostScript name (where font is the CGFont):

    let fontName = font?.postScriptName as String?
    textLabel.font = UIFont(name: fontName!, size: 17)
    

提交回复
热议问题