objective-c - NS_OPTIONS 个匹配项

标签 objective-c ios

我正在尝试实现以下 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/

相关文章:

ios 在构建字符串时我需要重用相同的占位符

iphone - 在服务器 iPhone 上上传图像

objective-c - 在 UIButton 上调用默认手势?

iphone - UIScrollView 旋转问题

ios - 从 BLOB(FMDB 结果)转换为 NSData 对象

ios - __destroy_helper_block_ 上的 Objective-C 崩溃

iphone - 关于 UITableView 和 deleteRowsAtIndexPaths 的问题

iphone - 如何知道在我的搜索显示 Controller 的搜索中选择的整个表格 View 中的行?

ios - Xcode 6.1 中缺少本地化

ios - 为什么从不调用 updatedTransactions?