我将UIButton上的UIImageView设置为图像,但是如果正在加载内容,则将该图像隐藏。然后,我将UIActivityIndicatorView添加到图像视图所在的位置。但是,当我触摸“标题”按钮时,图像视图突然出现,而没有更改hidden属性。它与我添加到按钮中的选择器/目标没有任何关系,因为我已将其注释掉。
按钮创建:
[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;
最佳答案
我认为隐藏图像的最好方法是将nil
设置为UIControlStateNormal
状态。更换
self.imageView.hidden = YES;
与
[self setImage:nil forState:UIControlStateNormal];