[http://www.jianshu.com/p/4f896df73d11](位运算和枚举 原文)
使用:直接上代码了
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger) {
CELL_TYPE_IMAGE = 1<<0,
CELL_TYPE_TEXT = 1<<1,
CELL_TYPE_VIP = 1<<2,
CELL_TYPE_PEOPLE = 1<<3
}CELL_TYPE;
@interface KapContentShowTableViewCell : UITableViewCell
@property (nonatomic,strong) UIView *vipView;
@property (nonatomic,strong) UIImageView *imageContentView;
@property (nonatomic,assign)CELL_TYPE type;
@end
#import "KapContentShowTableViewCell.h"
@implementation KapContentShowTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
self.type = CELL_TYPE_IMAGE|CELL_TYPE_VIP;// vip && 有图
}
- (void)setType:(CELL_TYPE)type{
if (type & CELL_TYPE_IMAGE) {
// 有图
[self.imageContentView mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(40);
}];
}
if (type & CELL_TYPE_TEXT) {
// 没图
[self.imageContentView mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.height.equalTo(0);
}];
}
if (type & CELL_TYPE_VIP) {
// 会员
self.vipView.hidden = NO;
}
if (type & CELL_TYPE_PEOPLE) {
// 普通人
self.vipView.hidden = YES;
}
[self layoutIfNeeded];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end