How do I create a bold UIFont from a regular UIFont?

后端 未结 7 1905
醉话见心
醉话见心 2020-12-08 19:08

If I have a UIFont object, is it possible to convert it to bold? I don\'t know the font name, I just have a UIFont object. What I want is a function like

<
7条回答
  •  执念已碎
    2020-12-08 20:00

    And if you are looking for the swift implementation:

    let normalFont = UIFont(name: "FONT_NAME", size: CGFloat(20))!
    let boldFont = UIFont(descriptor: normalFont.fontDescriptor.withSymbolicTraits(.traitBold)!, size: normalFont.pointSize)
    

    Hope this helps! Cheers!

提交回复
热议问题