为什么UIButton上的UIImageView会在触摸时重新出现?

时间:2013-11-01 20:06:16

标签: ios uiimageview uibutton

我将UIButton上的UIImageView设置为图像,但是如果正在加载则隐藏该图像。然后我将UIActivityIndi​​catorView添加到图像视图的位置。但是,当我触摸标题按钮时,图像视图突然出现而不更改隐藏属性。它与我添加到按钮的选择器/目标没有任何关系,因为我已经注释掉了。

按钮创建:

[button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor blueColor] forState:UIControlStateSelected];
[button setTitle:buttonTitles[i] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:buttonTitles[i]] forState:UIControlStateNormal];

在按钮类别中添加指标视图:

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[indicator startAnimating];
indicator.frame = self.imageView.frame;
[self addSubview:indicator];
self.imageView.hidden = YES;

1 个答案:

答案 0 :(得分:1)

我认为隐藏图片的最佳方法是为nil状态设置UIControlStateNormal。取代

self.imageView.hidden = YES;

[self setImage:nil forState:UIControlStateNormal];