美文网首页程序员iOS Developer@IT·互联网
iOS开发 枚举类型NS_ENUM和NS_OPTIONS的区别

iOS开发 枚举类型NS_ENUM和NS_OPTIONS的区别

作者: 槑头脑 | 来源:发表于2016-06-21 21:42 被阅读552次

NS_ENUM

通用枚举值

typedef NS_ENUM(NSInteger, UIControlContentHorizontalAlignment) {
    UIControlContentHorizontalAlignmentCenter = 0,
    UIControlContentHorizontalAlignmentLeft   = 1,
    UIControlContentHorizontalAlignmentRight  = 2,
    UIControlContentHorizontalAlignmentFill   = 3,
};

NS_OPTIONS

位移相关操作的枚举值

typedef NS_OPTIONS(NSUInteger, UIControlState) {
    UIControlStateNormal       = 0,
    UIControlStateHighlighted  = 1 << 0,
    UIControlStateDisabled     = 1 << 1,
    UIControlStateSelected     = 1 << 2,
    UIControlStateApplication  = 0x00FF0000,
    UIControlStateReserved     = 0xFF000000
};

  • 通常情况下我们用的枚举是NS_ENUM
  • 当一个枚举变量可能要代表多个属性的时候,就要用到NS_OPTIONS(NS_OPTIONS代表的也是一个值,只不过是两个或多个值按位移后的值)
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

给个喜欢喔O(∩_∩)O


相关文章

网友评论

    本文标题:iOS开发 枚举类型NS_ENUM和NS_OPTIONS的区别

    本文链接:https://www.haomeiwen.com/subject/lndgdttx.html