gpt4 book ai didi

objective-c - NS_OPTIONS 个匹配项

转载 作者:IT王子 更新时间:2023-10-29 08:07:10 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com