【发布时间】:2013-11-01 20:06:15
【问题描述】:
我将 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;
【问题讨论】:
-
更改你的问题的标题,这不是 UIImageView 只是 UIImage
-
不确定你的意思... UIButton 上的 imageView 属性是 UIImageView
-
是的,但是图像是您需要消失的。试试这个:
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; [indicator startAnimating]; indicator.frame = self.imageView.frame; [self addSubview:indicator]; [button setImage:nil forState:UIControlStateNormal];
标签: ios uiimageview uibutton