swift 2.0 将 UIFontDescriptorSymbolicTraits 转换为 CTFontSymbolicTraits

swift 2.0 convert UIFontDescriptorSymbolicTraits to CTFontSymbolicTraits

如何将 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;

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