ImageSlideshow

repository·master·Indexed 23 days ago

https://github.com/zvonicek/imageslideshow

A customizable Swift library for creating image slideshows featuring circular scrolling, timers, zooming, and a full-screen viewer. It supports various image loading sources including UIImage, Alamofire, AFNetworking, SDWebImage, Kingfisher, and Parse via the InputSource protocol.

Tokens
1.5K
Snippets
5
Records
7
Agent score
33%

What's inside ImageSlideshow

  1. Install ImageSlideshow via Carthage

    master

    To integrate ImageSlideshow using Carthage, add this line to your Cartfile:

    Note: Carthage does not include InputSources for external providers. You must manually retrieve the specific input source you need from ImageSlideshow/Classes/InputSources.

    github "zvonicek/ImageSlideshow" ~> 1.9.0
  2. Open Full Screen view

    master

    You can present the images in a full-screen viewer using the presentFullScreenController(from:) method. A common pattern is to add a tap gesture recognizer to the slideshow to trigger the full-screen mode.

    override func viewDidLoad() {
      let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(ViewController.didTap))
      slideshow.addGestureRecognizer(gestureRecognizer)
    }
    
    func didTap() {
      slideshow.presentFullScreenController(from: self)
    }
  3. Load images using setImageInputs

    master

    To populate the slideshow, use the setImageInputs method on your ImageSlideshow instance. This method accepts an array of objects conforming to the InputSource protocol.

    Commonly used InputSource types include:

    • ImageSource: For UIImage objects.
    • AlamofireSource: For Alamofire-based URL loading (requires pod "ImageSlideshow/Alamofire").
    • AFURLSource: For AFNetworking-based URL loading (requires pod "ImageSlideshow/AFURL").
    • SDWebImageSource: For SDWebImage-based URL loading (requires pod "ImageSlideshow/SDWebImage").
    • KingfisherSource: For Kingfisher-based URL loading (requires pod "ImageSlideshow/Kingfisher").
    • ParseSource: For Parse-based file loading (requires pod "ImageSlideshow/Parse").

    You can also implement the InputSource protocol to create custom sources.

    slideshow.setImageInputs([
      ImageSource(image: UIImage(named: "myImage"))!,
      ImageSource(image: UIImage(named: "myImage2"))!,
      AlamofireSource(urlString: "https://images.unsplash.com/photo-1432679963831-2dab49187847?w=1080"),
      KingfisherSource(urlString: "https://images.unsplash.com/photo-1432679963831-2dab49187847?w=1080"),
      ParseSource(file: PFFile(name:"image.jpg", data:data))
    ])
  4. Customize the Page Indicator

    master

    The pageIndicator property controls the visual indicator for current pages. By default, it uses a standard UIPageControl.

    Options:

    • Custom UIPageControl: Assign a configured UIPageControl instance.
    • LabelPageIndicator: A built-in indicator that shows text like "5/21".
    • Custom Indicator: Implement the PageIndicatorView protocol.

    To hide the indicator, set pageIndicator = nil.

    Positioning: Use pageIndicatorPosition with a PageIndicatorPosition object to set horizontal and vertical placement.

    • Horizontal options: .left(padding: Int), .center, .right(padding: Int)
    • Vertical options: .top, .bottom, .under, .customTop(padding: Int), .customBottom(padding: Int), .customUnder
    // Customizing a UIPageControl
    let pageIndicator = UIPageControl()
    pageIndicator.currentPageIndicatorTintColor = UIColor.lightGray
    pageIndicator.pageIndicatorTintColor = UIColor.black
    slideshow.pageIndicator = pageIndicator
    
    // Using the built-in LabelPageIndicator
    slideshow.pageIndicator = LabelPageIndicator()
    
    // Setting position
    slideshow.pageIndicatorPosition = PageIndicatorPosition(horizontal: .left(padding: 20), vertical: .bottom)
  5. Configure the Activity Indicator

    master

    The activity indicator is disabled by default. To enable it, assign a DefaultActivityIndicator instance to the activityIndicator property.

    Customization:

    • Style/Color: Use DefaultActivityIndicator(style:color:).
    • Custom Indicator: Implement the ActivityIndicatorView and ActivityIndicatorFactory protocols.
  6. Configure ImageSlideshow behavior

    master

    The ImageSlideshow instance provides several properties to customize its behavior:

    PropertyDescription
    slideshowIntervalInterval in seconds (default 0 – disabled)
    zoomEnabledEnables zooming (default false)
    circularEnables circular scrolling (default true)
    activityIndicatorCustom activity indicator (see Activity Indicator section)
    pageIndicatorCustom page indicator; assign nil to hide (see Page Indicator section)
    pageIndicatorPositionConfigures position of the page indicator
    contentScaleModeConfigures scaling (default ScaleAspectFit)
    draggingEnabledEnables dragging (default true)
    currentPageChangedClosure called when the page changes
    willBeginDraggingClosure called on scrollViewWillBeginDragging
    didEndDeceleratingClosure called on scrollViewDidEndDecelerating
    preloadImage preloading configuration (default all, also fixed)