位运算和枚举

[//www.greatytc.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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,256评论 25 709
  • 我看iOS本身定义的枚举里面经常会使用左移(<<)来定义枚举的值,一开始我还不懂为啥要这么定义。这么处理的逻辑跟i...
    FindCrt阅读 12,186评论 15 29
  • 我看iOS本身定义的枚举里面经常会使用左移(<<)来定义枚举的值,一开始我还不懂为啥要这么定义。这么处理的逻辑跟i...
    山中石头阅读 1,748评论 0 0
  • 303. Range Sum Query - Immutable:prefix_sum的一个简单应用 28. Im...
    健时总向乱中忙阅读 1,280评论 0 0
  • DAY12 (一)没有借口 到家门口了,饥肠辘辘,想吃一碗热腾腾的汤面条.去买呢还是自己做呢?还是自己做吧,冰箱里...
    青衣雨翼_shape阅读 2,515评论 0 0