0

我正在将 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;
4

1 回答 1

1

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

self.imageView.hidden = YES;

[self setImage:nil forState:UIControlStateNormal];
于 2013-11-01T20:25:42.047 回答