我有一个自定义按钮,点击该按钮后,我需要显示一个 Activity 指示器而不是标题标签。隐藏我使用的titleLabel
self.titleLabel.layer.opacity = 0.0f;
在该方法中,指标开始动画
- (void)startAnimating {
[self bringSubviewToFront: self.spinner];
self.titleLabel.layer.opacity = 0.0f;
[self.spinner startAnimating];
self.titleLabel.layer.opacity = ([self isAnimating]) ? 0.0f : 1.0f;
[self setNeedsDisplay];
}
它有效,但不能长时间使用。长按时,标题标签没有隐藏,标题上方出现 Activity 指示器。我试图在“startAnimating”中为标题设置颜色,它可以工作,但是我认为这不是一个好的解决方案。
如果有人可以提供帮助,将不胜感激:)
最佳答案
试试这个(快速):
@IBOutlet var buttonTap: UIButton!
var indicator = UIActivityIndicatorView()
@IBAction func buttonTap(_ sender: AnyObject) {
buttonTap.setTitle("", for: .normal)
indicator.center = buttonTap.center
indicator.color = UIColor.black
indicator.startAnimating()
}
关于ios - UIButton上的事件指示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40464509/