我正在尝试实现以下 typedef
typedef NS_OPTIONS (NSInteger, MyCellCorners) {
MyCellCornerTopLeft,
MyCellCornerTopRight,
MyCellCornerBottomLeft,
MyCellCornerBottomRight,
};
并正确地赋值
MyCellCorners cellCorners = (MyCellCornerTopLeft | MyCellCornerTopRight);
绘制单元格时,如何检查哪些选项匹配,以便正确绘制。
最佳答案
使用位掩码:
typedef NS_OPTIONS (NSInteger, MyCellCorners) {
MyCellCornerTopLeft = 1 << 0,
MyCellCornerTopRight = 1 << 1,
MyCellCornerBottomLeft = 1 << 2,
MyCellCornerBottomRight = 1 << 3,
};
MyCellCorners cellCorners = MyCellCornerTopLeft | MyCellCornerTopRight;
if (cellCorners & MyCellCornerTopLeft) {
// top left corner set
}
if (etc...) {
}
关于objective-c - NS_OPTIONS 个匹配项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13814733/