代码如下;
TF_LAZYLOAD_OBJC(UIButton, button1);
TF_LAZYLOAD_OBJC(UIButton, button2);
TF_LAZYLOAD_OBJC(UIButton, button3);
-
(id) initWithFrame:(CGRect)aRect {
self = [super initWithFrame:aRect];
if (self) {
kdeclare_weakself;
CGFloat buttonWidth = [UIScreen mainScreen].bounds.size.width/3;
[self.button1 easyCoder:^(UIButton *ins) {
[ins setTitle:@"收藏" forState:UIControlStateNormal];
[ins setBackgroundColor:[UIColor tf_randomColor]];
ins.tag = 1;
[ins addTarget:self action:@selector(buttonTouDown:) forControlEvents:UIControlEventTouchDown];
[weakSelf addSubview:ins];
[ins mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(weakSelf).offset(0);
make.top.equalTo(weakSelf).offset(0);
make.width.offset(buttonWidth);
make.height.offset(50);
}];
}];
[self.button2 easyCoder:^(UIButton *ins) {
[ins setTitle:@"订阅" forState:UIControlStateNormal];
[ins setBackgroundColor:[UIColor tf_randomColor]];
ins.tag = 2;
[ins addTarget:self action:@selector(buttonTouDown:) forControlEvents:UIControlEventTouchDown];
[weakSelf addSubview:ins];
[ins mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(weakSelf.button1.mas_right).offset(0);
make.top.equalTo(weakSelf).offset(0);
make.width.offset(buttonWidth);
make.height.offset(50);
}];
}];
[self.button3 easyCoder:^(UIButton *ins) {
[ins setTitle:@"夜间" forState:UIControlStateNormal];
[ins setBackgroundColor:[UIColor tf_randomColor]];
ins.tag = 3;
[ins addTarget:self action:@selector(buttonTouDown:) forControlEvents:UIControlEventTouchDown];
[weakSelf addSubview:ins];
[ins mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(weakSelf.button2.mas_right).offset(0);
make.top.equalTo(weakSelf).offset(0);
make.width.offset(buttonWidth);
make.height.offset(50);
}];
}];
}
return self;
}
第一个button的点击事件有,但是其他的就没有,这个是什么问题??
代码如下;
TF_LAZYLOAD_OBJC(UIButton, button1);
TF_LAZYLOAD_OBJC(UIButton, button2);
TF_LAZYLOAD_OBJC(UIButton, button3);
(id) initWithFrame:(CGRect)aRect {
self = [super initWithFrame:aRect];
if (self) {
kdeclare_weakself;
CGFloat buttonWidth = [UIScreen mainScreen].bounds.size.width/3;
[self.button1 easyCoder:^(UIButton *ins) {
[ins setTitle:@"收藏" forState:UIControlStateNormal];
[ins setBackgroundColor:[UIColor tf_randomColor]];
ins.tag = 1;
[ins addTarget:self action:@selector(buttonTouDown:) forControlEvents:UIControlEventTouchDown];
[weakSelf addSubview:ins];
[ins mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(weakSelf).offset(0);
make.top.equalTo(weakSelf).offset(0);
make.width.offset(buttonWidth);
make.height.offset(50);
}];
}];
[self.button2 easyCoder:^(UIButton *ins) {
[ins setTitle:@"订阅" forState:UIControlStateNormal];
[ins setBackgroundColor:[UIColor tf_randomColor]];
}
return self;
}
第一个button的点击事件有,但是其他的就没有,这个是什么问题??