不是换图片设置高亮那种 就是普通的一个按钮点击变色 有没有什么自带的方法 还是要去自定义 求解答 最好能给出代码
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方法