如何使用 Kingfisher 在 UIButton 的 setBackgroundImage 期间设置 indicatorType
How to set indicatorType during setBackgroundImage for UIButton using Kingfisher
在 Kingfisher 文档中有关于在为常规 imageView 设置图像时设置 indicatorType 的信息:
imageView.kf.indicatorType = .activity
imageView.kf.setImage(with: url)
但是UIButton设置背景图片时如何设置indicatorType呢?
myButton.kf.setBackgroundImage(with: url, for: .normal)
没有直接的方法
但您可以像这样创建带有指示器的自定义 UIButton
像那样
然后这样使用
let btn = LoadingButton()
btn.showLoading()
btn.kf.setBackgroundImage(with: URL(string: ""), for: .normal) { (image, error, cachType, url) in
btn.hideLoading()
}
在 Kingfisher 文档中有关于在为常规 imageView 设置图像时设置 indicatorType 的信息:
imageView.kf.indicatorType = .activity
imageView.kf.setImage(with: url)
但是UIButton设置背景图片时如何设置indicatorType呢?
myButton.kf.setBackgroundImage(with: url, for: .normal)
没有直接的方法
但您可以像这样创建带有指示器的自定义 UIButton
像那样
然后这样使用
let btn = LoadingButton()
btn.showLoading()
btn.kf.setBackgroundImage(with: URL(string: ""), for: .normal) { (image, error, cachType, url) in
btn.hideLoading()
}