1

我的每个 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)并替换前一个?

无论如何,请解释如何实现这个......

4

1 回答 1

3

最好的方法是使用多个图像。

您可以使用 setImage 方法将不同的图像设置为 UIButton 的不同状态。

如我所见,您仅为 UIControlStateNormal 状态设置了图像,这使得按钮的所有其他状态都使用相同的图像。

参考:UIButton 状态

希望这可以帮助。

于 2011-01-10T12:29:37.280 回答