/*冬天添加自定义UIButton*/
- (void) customBtn{
//设定背景色为透明的按钮处理,注意BUttonType是UIButtonTypeCustom
myBtn = [UIButton buttonWithType:UIButtonTypeCustom];
myBtn.backgroundColor = [UIColor clearColor];
myBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];//选择圆矩形外观
myBtn.frame = CGRectMake(100, 100, 100, 100);//设定button坐标宽高
[myBtn setTitle:@" 动态添加BUtton" forState:UIControlStateNormal];//选择正常外观
[myBtn addTarget:self action:@selector(btnDownAction:) forControlEvents:UIControlEventTouchDown];//添加按钮按下事件处理
[myBtn addTarget:self action:@selector(btnUpAction:) forControlEvents:UIControlEventTouchUpInside];//添加按钮离开
[self.view addSubview:myBtn];
}
/*按钮添加事件处理*/
- (IBAction) btnDownAction:(id)sender{
NSLog(@"按钮按下事件处理======");
//这里在按下的进行一个修改背景色的处理
}
/*按钮添加事件处理*/
- (IBAction) btnUpAction:(id)sender{
NSLog(@"按钮按下事件处理======");
//这里进行一个按钮背景色透明的处理
}
联系客服