随笔 - 0  文章 - 1  trackbacks - 0
<2024年11月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

常用链接

留言簿

文章分类

文章档案

搜索

  •  

最新评论

总结:当button的状态为selected的时候,高亮时对应的状态应该是selected|highlighted,这与normal下高亮的状态highlighted不同。

以下是stackover上的提问,附上:
I've a UIButton and I set it with:
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];

UIImage 
*imageNormal = [UIImage imageNamed:@"normal.png"];
UIImage 
*imageNormalHover = [UIImage imageNamed:@"normalHover.png"];
UIImage 
*imageSelected = [UIImage imageNamed:@"selected.png"];
UIImage 
*imageSelectedHover = [UIImage imageNamed:@"selectedHover.png"];

[myButton setImage:imageNormal forState:UIControlStateNormal];
[myButton setImage:imageSelected forState:UIControlStateSelected];

if (boolVar) {
    [myButton setSelected:YES];
    [myButton setImage:imageSelectedHover forState:UIControlStateHighlighted];
else {
    [myButton setImage:imageNormalHover forState:UIControlStateHighlighted];
}
The issue is when the state is normal and I try to press the button I see correctly the image normalHover.png but when the state is selected and I try to press the button I see still normalHover.png and not the selectedHover.png. It seems that with UIButton I'm unable to change the highlighted image. Do you how to solve?

Answer:
You need to set the image for the UIControlStateSelected | UIControlStateHighlighted combined state:
[myButton setImage:imageSelectedHover forState:(UIControlStateSelected | UIControlStateHighlighted)];
Because both states are on when the button is selected and you hignlight it by tapping on it.
posted on 2013-12-16 18:14 Long 阅读(5981) 评论(0)  编辑 收藏 引用 所属分类: iOS

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理