检查字体仅是粗体而不是加粗,半粗体或其他粗体 [英] Check font is only bold not extrabold, semibold or any ohter bold
本文介绍了检查字体仅是粗体而不是加粗,半粗体或其他粗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用font.fontDescriptor.symbolicTraits.contains(.traitBold)
,但是如果字体是semibold
,extra bold
或任何其他粗体类型,则此函数返回true.
i'm using font.fontDescriptor.symbolicTraits.contains(.traitBold)
but this function is returns true if font is semibold
, extra bold
or any other bold type.
我需要解决方案,因为我的字体为粗体,然后变为true,而semibold
,extra bold
或任何其他粗体,则为false.
i need solution for i have bold font then get true and i have semibold
, extra bold
or any other bold then get false.
推荐答案
您可以使用类似以下内容的
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
然后,您可以将重量与.bold
进行比较.
Then, you can compare the weight to .bold
.
这篇关于检查字体仅是粗体而不是加粗,半粗体或其他粗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文