【问题标题】:Why is UIImageView on UIButton reappearing on touch?为什么 UIButton 上的 UIImageView 会在触摸时重新出现?
【发布时间】:2013-11-01 20:06:15
【问题描述】:

我将 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;

【问题讨论】:

  • 更改你的问题的标题,这不是 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


【解决方案1】:

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

self.imageView.hidden = YES;

[self setImage:nil forState:UIControlStateNormal];

【讨论】:

  • 我怎样才能删除指示器视图并获取图片呢?
  • 子类化 UIButton 是一种选择吗?
猜你喜欢
  • 2010-10-30
  • 1970-01-01
  • 2014-08-12
  • 2022-01-23
  • 1970-01-01
  • 1970-01-01
  • 2016-05-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多