UIButton在处于selected的情况下点击的问题
[button setBackgroundImage:backImage forState:UIControlStateNormal]; [button setBackgroundImage:backImage forState:UIControlStateHighlighted]; [button setBackgroundImage:selecetedBackImage forState:UIControlStateSelected | UIControlStateHighlighted]; [button setBackgroundImage:selecetedBackImage forState:UIControlStateSelected]; [button setImage:iconImage forState:UIControlStateNormal]; [button setImage:iconImage forState:UIControlStateHighlighted]; [button setImage:iconImage forState:UIControlStateSelected|UIControlStateHighlighted]; [button setTitle:text forState:UIControlStateNormal]; [button.titleLabel setFont:[UIFont systemFontOfSize:12.0]];
自定义tabbar用button替代tabbaritem遇到了一个问题。就是在选中button的情况下,再次点击button,会变成默认的图片,看起来很不美观。
查了好久终于看到原来还是state的原因。
UIControlStateSelected | UIControlStateHighlighted
UIControlStateSelected
这俩代表的不同,UIControlStateSelected | UIControlStateHighlighted 是处于selected 的情况下,再次点击高亮的效果。