枚举NS_OPTIONS与NS_ENUM
2017-04-19 本文已影响6人
垚子
NS_ENUM
typedef NS_ENUM(int,Banner){
banner_Init =0, //启动页 0
banner_Home, //首页1
banner_FindJob, //找工作2
banner_train ,//培训3
banner_Shopping, //商城4
};
大括号中的枚举项的值可自定义,若是定义了枚举项其中一项的值后面依次在它的前一项的值上加1
NS_OPTIONS
typedef NS_OPTIONS(NSUInteger, UISwipeGestureRecognizerDirection) {
UISwipeGestureRecognizerDirectionNone = 0, //值为0
UISwipeGestureRecognizerDirectionRight = 1 << 0, //值为2的0次方
UISwipeGestureRecognizerDirectionLeft = 1 << 1, //值为2的1次方
UISwipeGestureRecognizerDirectionUp = 1 << 2, //值为2的2次方
UISwipeGestureRecognizerDirectionDown = 1 << 3 //值为2的3次方
};
位移枚举即是在你需要的地方可以同时存在多个枚举值如这样:
UISwipeGestureRecognizer *swipeGR = [[UISwipeGestureRecognizer alloc] init];
swipeGR.direction = UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight;
//这里几个枚举项同时存在表示它的方向同时包含1.向下2.向左3.向右
而NS_ENUM定义的枚举不能几个枚举项同时存在,只能选择其中一项,像这样:
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
paragraph.baseWritingDirection = NSWritingDirectionNatural;