//UIButton比UILable, UITextfield多了一个能够让用户点击并且响应的功能(点击事件)
- (void)creatButton
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.backgroundColor = [UIColor brownColor];
button.frame = CGRectMake(110, 190, 100, 40);
//设置圆角
button.layer.cornerRadius = 8;
//给Button添加点击事件 让target执行action操作, 在ControlEvent发生之后 click后边的参数是: 谁调用了addTarget:action:方法, 参数就是谁, 而且参数只能有一个
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
//设置标题文字
[button setTitle:@"我打" forState:UIControlStateNormal];
//改变文字的颜色
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_bgView addSubview:button];
}
- (void)click:(UIButton *)button
{
NSLog(@"%@", button);
NSLog(@"我打..");
}
UIButton
最新推荐文章于 2024-08-01 11:20:03 发布