Check font is only bold not extrabold, semibold or any ohter bold

后端 未结 1 518
梦毁少年i
梦毁少年i 2021-01-24 00:54

i\'m using font.fontDescriptor.symbolicTraits.contains(.traitBold) but this function is returns true if font is semibold, extra bold or an

相关标签:
1条回答
  • 2021-01-24 01:35

    You can use something like:

    let attributes = font.fontDescriptor.fontAttributes
    let traits = attributes[.traits] as? [UIFontDescriptor.TraitKey : Any]
    let weight = traits[.weight] as? UIFont.Weight
    

    Then, you can compare the weight to .bold.

    0 讨论(0)
提交回复
热议问题