Skip to content

A simple and lightweight 'Image Slide View' for iOS written by Swift with UICollectionView and UIPageControl(No dependencies). You can use it easily with the complete demo. 🇨🇳

License

Notifications You must be signed in to change notification settings

pangpingfei/SimpleImageSlider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleImageSlider

Swift Version Carthage compatible License

A simple and lightweight 'Image Slide View' for iOS written by Swift with UICollectionView and UIPageControl(No dependencies). You can use it easily with the complete demo. 中文说明文档

Demo


Requirements

  • iOS 8.0 +
  • Xcode 8.0 +
  • Swift 3.0 +

Installation

Carthage (Recommend)

中文简易教程Github](https://github.com/pangpingfei/SwiftBlog/blob/master/Others/Carthage.md) | [中文简易教程Jianshu

Create a Cartfile that lists the framework and run carthage update. Follow the instructions to add $(SRCROOT)/Carthage/Build/iOS/SimpleImageSlider.framework to an iOS project.

github "pangpingfei/SimpleImageSlider"

Run carthage update --platform iOS to build the framework and drag the built SimpleImageSlider.framework into your Xcode project.

To get the full benefits import SimpleImageSlider

import SimpleImageSlider

Manually

  1. Download and drop SimpleImageSlider.swift into your project.
  2. Congratulations!

Usage

Implement 'SimpleImageSliderData'

// your own class or struct
struct MyData {
	var id: String?
	var image: UIImage?
	var imageUrl: String?
}
extension MyData: SimpleImageSliderData {
	public func setImage(for imageView: UIImageView) {
		imageView.image = self.image
		// in this func you can also load a network image
	}
}

Init SimpleImageSlider

// init a slider
let frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.width/2)
slider = SimpleImageSlider(frame: frame, dateSource: self, delegate: self)
		
// setup slider's pageControl if necessary
slider.currentPageIndicatorColor = nil //.black
slider.pageIndicatorColor = nil //.gray
slider.hidePageControlForSinglePage = true

// 		slider = SimpleImageSlider(frame: frame)		
// setup slider's delegate and dateSource, if you use init(frame) func.
//		slider.delegate = self
//		slider.dataSource = self
		
// add to your view
self.view.addSubview(slider)

// if you want to stop or start sliding automatic, set isEnableAutoSlide.
slider.isEnableAutoSlide = false

Implement 'SimpleImageSliderDataSource'

func simpleImageSlider(_ imageSlider: SimpleImageSlider) -> [SimpleImageSliderData] {
	return data
}
fileprivate var data = [MyData]()

// prepare for dataSource
for i in 1...3 {
	if let image = UIImage(named: "\(i)") {
		data.append(MyData(id: "\(i)", image: image, imageUrl: nil))
	} else {
		break
	}
}

Implement 'SimpleImageSliderDelegate'

func simpleImageSlider(_ imageSlider: SimpleImageSlider, didTouchImageAt imageSliderData: SimpleImageSliderData) {
	// do what your want to do
	let msg = "simpleImageSlider didTouchImageAt \((imageSliderData as! MyData).id!)"
	print(msg)
}

Attention!!!

// if your datasource updated, call this function
slider.reloadData()
// if you want to deinit, set isEnableAutoSlide to false
// also, if your view is invisible, you should set false, and set true when view is visible
// such as, 'viewDidAppear': slider.isEnableAutoSlide = true, 'viewWillDisappear': slider.isEnableAutoSlide = false
slider.isEnableAutoSlide = false

More...

For more information please see the demo in project.

License

SimpleImageSlider is available under the MIT license. See the LICENSE file.

About

A simple and lightweight 'Image Slide View' for iOS written by Swift with UICollectionView and UIPageControl(No dependencies). You can use it easily with the complete demo. 🇨🇳

Resources

License

Stars

Watchers

Forks

Packages

No packages published