Apple 提供了一个宏。这增加了最显着的自动完成。
typedef NS_ENUM(NSInteger, UITableViewCellStyle) {
UITableViewCellStyleDefault = 0,
UITableViewCellStyleValue1,
UITableViewCellStyleValue2,
UITableViewCellStyleSubtitle
};
用于不同的值。
如果您想对选项进行位掩码,其中几个可以一起使用,请使用NS_OPTIONS
typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) {
UIViewAutoresizingNone = 0,
UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
UIViewAutoresizingFlexibleWidth = 1 << 1,
UIViewAutoresizingFlexibleRightMargin = 1 << 2,
UIViewAutoresizingFlexibleTopMargin = 1 << 3,
UIViewAutoresizingFlexibleHeight = 1 << 4,
UIViewAutoresizingFlexibleBottomMargin = 1 << 5
};
用作位掩码
UIViewAutoresizing resizing = (UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin)
如果您希望能够从类外部设置,请将其添加到头文件中
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSUInteger, InsetCellAlignment){
InsetCellAlignmentLeft,
InsetCellAlignmentRight
};
@interface InsetCell : UITableViewCell
@property InsetCellAlignment alignment;
@property(nonatomic)CGFloat inset;
@end
如果您需要以某种状态扩展 UIButton,这强烈表明您没有正确使用 MVC。控制器应该知道状态并分别配置按钮。
也就是说,您可以使用“关联引用”来获得所需的结果,该引用可用于模拟添加的成员变量。 IMO 它们很臭,我从未使用过它们。
A category used along with associative references