Ariel Gemilang
Ariel Gemilang

Reputation: 791

How to Make Loading in Image Slideshow Swift

so, i'm using swift library ImageSlideshow and use KingfisherSource to set image. I get the url image from Alamofire request

How to make loading/activity indicator before image showed?

Here's my code:

var arrayImage = [InputSource]()

for data in items{                  
      let Menu = ModelBanner()                  
      Menu.id = (data["id"].intValue)
      Menu.banner = (data["banner"].stringValue)
      self.listBanner.append(Menu)
      self.arrayImage.append(KingfisherSource(urlString: data["banner"].stringValue)!)                       
    }
      self.slideImage.contentScaleMode = .scaleAspectFill
      self.slideImage.setImageInputs(self.arrayImage)

Upvotes: 1

Views: 1577

Answers (2)

Bilal
Bilal

Reputation: 19156

Better way to show activity indicator is to use the default implementation.

slideshow.activityIndicator = DefaultActivityIndicator()

You can customize style and color of the indicator:

slideshow.activityIndicator = DefaultActivityIndicator(style: .white, color: nil)

There's also an option to use your own activity indicator. You just need to implement ActivityIndicatorView and ActivityIndicatorFactory protocols.

For more details see the Activity Indicator section here.

Upvotes: 0

Ennabah
Ennabah

Reputation: 2513

  1. You can add activity indicator from the storyboard over your UIImageView.
  2. Connect an outlet from the activity indicator to your ViewController file
  3. In viewDidLoad(), activityIndicator.hidesWhenStopped = true
  4. Within your Alamofire request, use activityIndicator.startAnimating()
  5. Once you get the call back from Alamofire, in the completion handler, use activityIndicator.stopAnimating()

Above code assumes activityIndicator is the outlet connection name of the UIActivityIndicatorView

Upvotes: 1

Related Questions