RTButton.m
#import "RTButton.h"
@implementation RTButton
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if(!self) {
}
return self;
}
- (RTButton * (^)(UIColor * color))btnNC {
return ^(UIColor *color) {
[self setTitleColor:color forState:UIControlStateNormal];
return self;
};
}
- (RTButton * _Nonnull (^)(UIColor * _Nonnull))btnSC {
return ^(UIColor *color) {
[self setTitleColor:color forState:UIControlStateSelected];
return self;
};
}
@end
ViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor grayColor];
RTButton *btn = [RTButton buttonWithType:UIButtonTypeCustom];
btn.backgroundColor = [UIColor whiteColor];
[btn setTitle:@"Click Me" forState:UIControlStateNormal];
btn.frame = CGRectMake(50, 100, 100, 60);
btn.btnSC([UIColor redColor]).btnNC([UIColor blueColor]);
[btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
网友评论