如何将UIFontDescriptorSymbolicTraits转换为CTFontSymbolicTraits

最佳答案

看一下它们是如何定义的。这是CTFontSymbolicTraits:

enum {
kCTFontItalicTrait = (1 << 0),
kCTFontBoldTrait = (1 << 1),
kCTFontExpandedTrait = (1 << 5),
kCTFontCondensedTrait = (1 << 6),
// ...
};
typedef uint32_t CTFontSymbolicTraits;


这是UIFontDescriptorSymbolicTraits:

typedef enum : uint32_t {
   UIFontDescriptorTraitItalic = 1u << 0,
   UIFontDescriptorTraitBold = 1u << 1,
   UIFontDescriptorTraitExpanded = 1u << 5,
   UIFontDescriptorTraitCondensed = 1u << 6,
   // ...
} UIFontDescriptorSymbolicTraits;


注意到什么了吗?就您而言重要的特征而言,它们实际上是相同的。没有什么可以转换的。

07-26 09:37