我正在将 UIButton 上的 UIImageView 设置为图像,但如果正在加载某些内容,则隐藏该图像。然后,我将 UIActivityIndicatorView 添加到图像视图所在的位置。但是,当我触摸按钮标题时,图像视图突然出现而没有更改隐藏属性。它与我添加到按钮的选择器/目标没有任何关系,因为我已经将其注释掉了。
按钮创建:
[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;