Ariel Gemilang Ariel Gemilang - 3 years ago 149
Swift Question

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() = (data["id"].intValue)
Menu.banner = (data["banner"].stringValue)
self.arrayImage.append(KingfisherSource(urlString: data["banner"].stringValue)!)
self.slideImage.contentScaleMode = .scaleAspectFill

Answer Source
  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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download