首页 > 代码库 > button设为UICustomType后点击无高亮效果

button设为UICustomType后点击无高亮效果

今天在cell上加了一个button,设了image

secondButton.buttonType = UIButtonTypeCustom;

[secondButton setImage:image_2 forState:UIControlStateNormal];

但是点击上去无高亮效果,经查找

发现两个问题

1、应该设backGroundImage

[secondButton setBackgroundImage:image_2 forState:UIControlStateNormal];

2、设置属性为YES

secondButton.showsTouchWhenHighlighted = YES;

修改了以上两点后,button就显示出高亮效果了。