#import "TestController.h"
@interface TestController ()
@property (strong, nonatomic)UIButton *btn;
@end
@implementation TestController
- (void)viewDidLoad {
[super viewDidLoad];
//获取标题
NSString*s1 = [self.btn titleForState:UIControlStateNormal];
//获取颜色
UIColor*color1 = [self.btn titleColorForState:UIControlStateNormal];
}
#pragma mark - lazyload
- (UIButton *)btn{
if (!_btn) {
_btn = [UIButton buttonWithType:UIButtonTypeSystem];
_btn.backgroundColor = [UIColor grayColor];
// 设置标题
[_btn setTitle:@"点我啊"forState:UIControlStateNormal];
[self.view addSubview: _btn];
//设置前景图片(1.覆盖标题2.不会拉伸3.必须是镂空图)
//[btn setImage:[UIImage imageNamed:@"2x.png"] forState:UIControlStateNormal];
//设值背景图片
//[btn setBackgroundImage:[UIImage imageNamed:@"11"] forState:UIControlStateNormal];
//设置标题颜色
[_btn setTitleColor:[UIColor redColor]forState:UIControlStateNormal];
//设置阴影
[_btn setTitleShadowColor:[UIColor greenColor]forState:UIControlStateNormal];
[_btn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.offset(100);
make.size.mas_equalTo(CGSizeMake(100, 100));
}];
[_btn bk_addEventHandler:^(id _Nonnull sender) {
NSLog(@"点击了按钮");
} forControlEvents:UIControlEventTouchUpInside];
}
return _btn;
}
@end
网友评论