问题描述
解决方案
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(200, 200, 100, 40);
button.backgroundColor = [UIColor redColor];
[button setTitle:@"点击" forState:UIControlStateNormal];
button.tag = 10;
[button setTitle:@"未点击" forState:UIControlStateSelected];
[button addTarget:self action:@selector(changeBackColor) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
-(void)changeBackColor{
UIButton *button = (UIButton *)[self.view viewWithTag:10];
if (button.selected != YES) {
button.backgroundColor = [UIColor greenColor];
button.selected =YES;
}else{
button.backgroundColor = [UIColor redColor];
button.selected = NO;
}
}
解决方案二:
楼主是说点击的高亮效果 还是说点击后 更改状态 ?
解决方案三:
button 有一个show touch on heightlighted,这种的可以做到
解决方案四:
自定义Uibutton,重新set方法
时间: 2024-10-27 19:08:49