Search code examples
iosswiftkingfisher

How to set indicatorType during setBackgroundImage for UIButton using Kingfisher


In Kingfisher documentation there is information about setting indicatorType when set image for regular imageView:

    imageView.kf.indicatorType = .activity
    imageView.kf.setImage(with: url)

But how to set indicatorType when set background image for UIButton?

    myButton.kf.setBackgroundImage(with: url, for: .normal)

Solution

  • No direct way to do that

    but you can do it like that create Custom UIButton with indicator like that

    Display activity indicator inside UIButton

    Then use like this

    let btn = LoadingButton()
        btn.showLoading()
        btn.kf.setBackgroundImage(with: URL(string: ""), for: .normal) { (image, error, cachType, url) in
          btn.hideLoading()
        }