我在每个tableview的单元格中都有一个UIButton。我想在点击动作发生的时候让uibutton发光。我使用下面的代码将一张图像设置为其背景图像
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(270,10,30,30);
[button setImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor = [UIColor clearColor];image.png是稍微暗一点的图像。因为我想通过显示发光的图像来显示点击效果。
现在,当单击发生时,我应该通过代码使image.png发光吗?或者我应该创建一个具有相同尺寸的新发光图像(例如image_glow.png)并替换以前的图像?
无论如何,请解释一下如何实现这一点...
发布于 2011-01-10 20:29:37
最好的方法是使用多个图像。
您可以使用setImage方法将不同的图像设置为UIButton的不同状态。
正如我所看到的,您只为UIControlStateNormal状态设置了图像,这使得按钮的所有其他状态都使用相同的图像。
参考:UIButton States
希望这能有所帮助。
https://stackoverflow.com/questions/4646628
复制相似问题