Swift Image Slider library for iOS

Related tags

Image banana
Overview

Banana - ImageSlider for Swift

Swift 2.0 CocoaPods

Image slider with very simple interface.

At a Glance

@IBOutlet weak var imageScrollView: UIScrollView!
// Here imageArray can be a string array of Image URLs 
var imageArray = [String]()

//or imageArray can be a array of UIImages
var imageArray = [UIImage]()

var imageScroll = banana( imageScrollView :self.imageScrollView )
//Load to load images in memory and display them in User Interface
imageScroll!.load(imageArray)

//Call startScroll for autoScrolling. Default scrolling timer is 8 seconds
imageScroll!.startScroll()

//Call this function to stop autoScrolling on touch or swipe.
imageScroll!.assignTouchGesture()

Features

  • Objective-C Compatible: import banana.h to use Banana in Objective-C.
  • Customizable: see [Advanced] section.

Installation

  • For iOS 8+ projects with Carthage:

    github "gauravkatoch007/banana" ~> 1.0
    
  • For iOS 7 projects: I recommend you to try CocoaSeeds, which uses source code instead of dynamic frameworks. Sample Seedfile:

    github 'gauravkatoch007/banana', '1', :files => 'banana/*.{swift,h}'

Objective-C

banana is compatible with Objective-C. What you need to do is to import a auto-generated header file:

#import <banana/banana.h>

Setting AutoScroll Delay and Caching threshold

var imageScroll = banana( imageScrollView :self.imageScrollView )
imageScroll.autoScrollTime = 2 // < Any integer value in seconds >

//banana library doesn't load all images at once in memory, but only some images (one in display and one or two before and after are loaded). Images are loaded and unloaded dynamically. Default is 4
imageScoll.imagesToLoadInMemory = 10

Advanced

//You can also assign a UIPageControl.
@IBOutlet weak var imageScrollView: UIScrollView!
@IBOutlet weak var imagePageControl: UIPageControl!

var imageScroll = banana( imageScrollView :self.imageScrollView, imagePageControl : self.imagePageControl )
self.imageScroll!.load(imageArray)
self.imageScroll!.startScroll()
self.imageScroll!.assignTouchGesture()

Screenshots

License

banana is released under the MIT license. See LICENSE file for more info.

You might also like...
Simple image crop library for iOS
Simple image crop library for iOS

PhotoCropper This is a simple image crop library for iOS I made for fun on Chris

FlaneurImagePicker is an iOS image picker that allows users to pick images from different sources (ex: user's library, user's camera, Instagram...).                            It's highly customizable.
FlaneurImagePicker is an iOS image picker that allows users to pick images from different sources (ex: user's library, user's camera, Instagram...). It's highly customizable.

FlaneurImagePicker is a highly customizable iOS image picker that allows users to pick images from different sources (ex: device's library, device's c

🍁πŸ₯“ Lightweight and fast Swift library for image downloading, caching and transformations
🍁πŸ₯“ Lightweight and fast Swift library for image downloading, caching and transformations

MapleBacon Introduction MapleBacon is a lightweight and fast Swift library for downloading and caching images. Example The folder Example contains a s

A high-performance image library for downloading, caching, and processing images in Swift.
A high-performance image library for downloading, caching, and processing images in Swift.

Features Asynchronous image downloader with priority queuing Advanced memory and database caching using YapDatabase (SQLite) Guarantee of only one ima

AlamofireImage is an image component library for Alamofire

AlamofireImage AlamofireImage is an image component library for Alamofire. Features Image Response Serializers UIImage Extensions for Inflation / Scal

Image filtering UI library like Instagram.
Image filtering UI library like Instagram.

Sharaku Usage How to present SHViewController let imageToBeFiltered = UIImage(named: "targetImage") let vc = SHViewController(image: imageToBeFiltered

A apple music cover picture shadow style image library
A apple music cover picture shadow style image library

ShadowImageView A apple music cover picture shadow style image library ShadowImageView is a iOS 10 Apple Music style image view, help you create elege

Slide image viewer library similar to Twitter and LINE.
Slide image viewer library similar to Twitter and LINE.

Overview You can use it simply by passing the necessary information! Serrata is a UI library that allows you to intuitively view images. Features King

React-native-image-generator - Library to generate images from layers
React-native-image-generator - Library to generate images from layers

react-native-image-generator Library for generate images from other images Insta

Comments
  • Here is an updated version for swift 4

    Here is an updated version for swift 4

    //
    //  banana.swift
    //  banana
    //
    //  Created by cdp  on 11/9/15.
    //  Copyright Β© 2015 Katoch. All rights reserved.
    //
    
    import Foundation
    import UIKit
    
    public class banana : UIViewController, UIScrollViewDelegate {
        
        var imagePageControl: UIPageControl?
        var imageScrollView: UIScrollView!
        var pageImages: [UIImage] = []
        var pageViews: [UIImageView?] = []
        var timer : Timer = Timer()
        var imagesLoaded = false
        public var autoScrollTime : Double = 8
        public var imagesToLoadInMemory = 4
        
        public convenience init ( imageScrollView : UIScrollView, imagePageControl : UIPageControl? = nil){
            self.init()
            self.imageScrollView = imageScrollView
            self.imageScrollView.delegate = self
            self.imagePageControl = imagePageControl
            
        }
    
    //    required public init?(coder aDecoder: NSCoder) {
    //        fatalError("init(coder:) has not been implemented")
    //    }
        
        @nonobjc public func load(imagesArrayInput : [String]){
            DispatchQueue.global(qos: .default).async {
                // do some task
                self.getScrollViewImages(imagesArrayInput)
                DispatchQueue.main.async {
                    // update some UI
                    self.loadScrollViewImages()
                }
            }
            
        }
        
        @nonobjc public func load(imagesArrayInput : [UIImage]){
            DispatchQueue.global(qos: .default).async {
                // do some task
                self.getScrollViewImages(imagesArrayInput)
                DispatchQueue.main.async {
                    // update some UI
                    self.loadScrollViewImages()
                }
            }
        }
        
        public func startScroll(){
            timer = Timer.scheduledTimer(timeInterval: autoScrollTime, target: self, selector: #selector(autoScrollImage), userInfo: nil, repeats: true)
        }
        
        public func stopScroll(){
            timer.invalidate()
        }
        
        
        
        @nonobjc func getScrollViewImages(_ imagesArray : [String]){
            for image in imagesArray {
                if let url = NSURL(string: image) {
                    if let data = NSData(contentsOf: url as URL){
                        pageImages.append(UIImage(data: data as Data)!)
                    }
                }
            }
        }
        
        @nonobjc func getScrollViewImages(_ imagesArray : [UIImage]){
            for image in imagesArray {
                pageImages.append(image)
            }
        }
        
        func loadScrollViewImages(){
            let pageCount = pageImages.count
            
            // 2
            if imagePageControl != nil {
                imagePageControl!.currentPage = 1
                imagePageControl!.numberOfPages = pageCount
            }
            
            // 3
            for _ in 0..<pageCount {
                pageViews.append(nil)
            }
            
            // 4
            let pagesScrollViewSize = imageScrollView.frame.size
            imageScrollView.contentSize = CGSize(width: pagesScrollViewSize.width * CGFloat(pageImages.count),
                height: pagesScrollViewSize.height)
            
            // 5
            self.imagesLoaded = true
            loadVisiblePages()
        }
        
        func loadPage(page: Int) {
            if page < 0 || page >= pageImages.count {
                // If it's outside the range of what you have to display, then do nothing
                return
            }
            
            // 1
            if pageViews[page] != nil {
                // Do nothing. The view is already loaded.
            } else {
                // 2
                var frame = imageScrollView.bounds
                frame.origin.x = frame.size.width * CGFloat(page)
                frame.origin.y = 0.0
                //            frame = CGRectInset(frame, 10.0, 0.0)
                
                // 3
                let newPageView = UIImageView(image: pageImages[page])
                newPageView.contentMode = .scaleAspectFit
                newPageView.frame = frame
                imageScrollView.addSubview(newPageView)
                
                // 4
                pageViews[page] = newPageView
            }
        }
        
        func purgePage(page: Int) {
            if page < 0 || page >= pageImages.count {
                // If it's outside the range of what you have to display, then do nothing
                return
            }
            
            // Remove a page from the scroll view and reset the container array
            if let pageView = pageViews[page] {
                pageView.removeFromSuperview()
                pageViews[page] = nil
            }
        }
        
        public func loadVisiblePages() {
            // First, determine which page is currently visible
            let pageWidth = imageScrollView.frame.size.width
            var page = Int(floor((imageScrollView.contentOffset.x * 1.0 + pageWidth) / (pageWidth * 1.0))) - 1
            if page >= pageImages.count {
                page = 0
            }
            // Update the page control
            if imagePageControl != nil {
                imagePageControl!.currentPage = page
            }
            
            // Work out which pages you want to load
            let firstPage = page - ( imagesToLoadInMemory / 2 )
            let lastPage = page + ( imagesToLoadInMemory / 2 )
            
            print("First Page ="+String(firstPage))
            print("Last Page ="+String(lastPage))
            
            // Purge anything before the first page
            for index in stride(from: 0, to: firstPage, by: 1) {
                purgePage(page: index)
                
            }
            
            // Load pages in our range
            for index in firstPage...lastPage {
                loadPage(page: index)
            }
            
            // Purge anything after the last page
            for index in stride(from: 0, to: pageImages.count, by: 1) {
                purgePage(page: index)
            }
            
        }
        
        
        @objc public func autoScrollImage (){
            
            let pageWidth:CGFloat = self.imageScrollView.frame.width
            let maxWidth:CGFloat = pageWidth * CGFloat(pageImages.count)
            let contentOffset:CGFloat = self.imageScrollView.contentOffset.x
            
            var slideToX = contentOffset + pageWidth
            
            if  contentOffset + pageWidth == maxWidth{
                slideToX = 0
            }
    
            self.imageScrollView.scrollRectToVisible(CGRect(x: slideToX, y: 0, width: pageWidth, height: self.imageScrollView.frame.height), animated: true)
        }
        
        public func assignTouchGesture(){
    //        let tapRecognizer = UITapGestureRecognizer(target: self, action: "scrollViewTapped:")
            let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(scrollViewTapped(recognizer:)))
            
            tapRecognizer.numberOfTapsRequired = 1
            //        tapRecognizer.numberOfTouchesRequired = 1
            self.imageScrollView.addGestureRecognizer(tapRecognizer)
            
            let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture(gesture:)))
            swipeRight.direction = UISwipeGestureRecognizerDirection.right
            self.imageScrollView.addGestureRecognizer(swipeRight)
            
            let swipeLeft = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture(gesture:)))
            swipeLeft.direction = UISwipeGestureRecognizerDirection.left
            self.imageScrollView.addGestureRecognizer(swipeLeft)
            
            let swipeUp = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture(gesture:)))
            swipeUp.direction = UISwipeGestureRecognizerDirection.up
            self.imageScrollView.addGestureRecognizer(swipeUp)
            
            let swipeDown = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture(gesture:)))
            swipeDown.direction = UISwipeGestureRecognizerDirection.down
            self.imageScrollView.addGestureRecognizer(swipeDown)
        }
        @objc public func scrollViewTapped(recognizer: UITapGestureRecognizer){
            timer.invalidate()
            if self.imagesLoaded == true {
                loadVisiblePages()
            }
        }
        
        @objc public func respondToSwipeGesture(gesture: UIGestureRecognizer) {
            timer.invalidate()
            if self.imagesLoaded == true {
                loadVisiblePages()
            }
        }
        
        @objc public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
            if self.imagesLoaded == true {
                loadVisiblePages()
            }
        }
        
        @objc public func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
            if self.imagesLoaded == true {
                loadVisiblePages()
            }
        }
    
    }
    
    
    opened by rami965 1
  • Can you add some screenshots?

    Can you add some screenshots?

    Your sample app not working with Swift 3 out of the box - maybe it is time to update it? Also It will be very helpful if you can add some screenshots to project description.

    opened by moonvader 1
  • Dependency

    Dependency "banana" has no shared framework schemes

    MacBook-Air-Walter:UICollectionView anton$ carthage update *** Fetching banana *** Checking out banana at "1.0" *** xcodebuild output can be found in /var/folders/sw/hrlh1bqj55d_2x1y8d252l4r0000gn/T/carthage-xcodebuild.Svpjar.log *** Skipped building banana due to the error: Dependency "banana" has no shared framework schemes

    If you believe this to be an error, please file an issue with the maintainers at https://github.com/gauravkatoch007/banana/issues/new

    opened by heisen273 1
  • Support asynchronous loading of big collections

    Support asynchronous loading of big collections

    Please support, that when the first image has been loaded it will be displayed. Currently all images has been loaded completely before the first image gets visible

    opened by ogezue 1
Releases(1.0)
Owner
Gaurav Katoch
Programmer, hackathon winner, traveller, Googler.
Gaurav Katoch
An image download extension of the image view written in Swift for iOS, tvOS and macOS.

Moa, an image downloader written in Swift for iOS, tvOS and macOS Moa is an image download library written in Swift. It allows to download and show an

Evgenii Neumerzhitckii 330 Sep 9, 2022
AsyncImage before iOS 15. Lightweight, pure SwiftUI Image view, that displays an image downloaded from URL, with auxiliary views and local cache.

URLImage URLImage is a SwiftUI view that displays an image downloaded from provided URL. URLImage manages downloading remote image and caching it loca

Dmytro Anokhin 1k Jan 4, 2023
Twitter Image Pipeline is a robust and performant image loading and caching framework for iOS clients

Twitter Image Pipeline (a.k.a. TIP) Background The Twitter Image Pipeline is a streamlined framework for fetching and storing images in an application

Twitter 1.8k Dec 17, 2022
Image-cropper - Image cropper for iOS

Image-cropper Example To run the example project, clone the repo, and run pod in

Song Vuthy 0 Jan 6, 2022
πŸ“· A composable image editor using Core Image and Metal.

Brightroom - Composable image editor - building your own UI Classic Image Editor PhotosCrop Face detection Masking component ?? v2.0.0-alpha now open!

Muukii 2.8k Jan 3, 2023
πŸ“· A composable image editor using Core Image and Metal.

Brightroom - Composable image editor - building your own UI Classic Image Editor PhotosCrop Face detection Masking component ?? v2.0.0-alpha now open!

Muukii 2.8k Jan 2, 2023
A complete Mac App: drag an image file to the top section and the bottom section will show you the text of any QRCodes in the image.

QRDecode A complete Mac App: drag an image file to the top section and the bottom section will show you the text of any QRCodes in the image. QRDecode

David Phillip Oster 2 Oct 28, 2022
Convert the image to hexadecimal to send the image to e-paper

ConvertImageToHex Convert the image to hexadecimal to send the image to e-paper Conversion Order // 0. hex둜 λ³€ν™˜ν•  이미지 var image = UIImage(named: "sample

Hankyeol Park 0 Feb 26, 2022
An instagram-like image editor that can apply preset filters passed to it and customized editings to a binded image.

CZImageEditor CZImageEditor is an instagram-like image editor with clean and intuitive UI. It is pure swift and can apply preset filters and customize

null 8 Dec 16, 2022
A very useful and unique iOS library to open image picker in just few lines of code.

ImagePickerEasy A very simple solution to implement UIImagePickerController() in your application. Requirements Swift 4.2 and above Installation Image

wajeehulhassan 6 May 13, 2022