TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Nov 2016 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✗ |
Maintained by Enix Yu.
A simple image slider written in Swift for iOS8 and up, inspired by KIImagePager
include the following line into your podfile
pod EYImageSlider
and run
pod install
Simply copy EYImageSlider/EYImageSlider.swift
to your project
You can create an EYImageSlider either from Storyboard or programatically EYImageSlider()
Drag a UIView into storyboard, and set the UIView Class to EYImageSlider
.
Set an outlet for the image slider to the view controller.
@IBOutlet weak var imageSlider: EYImageSlider!
Set the image slider data source and delegete
// Set slider data source & delegate
imageSlider.dataSource = self
imageSlider.delegate = self
Implement the data source protocol:
images = [
NSURL(string:"http://ocr68xaax.bkt.clouddn.com/images/product/a0d19e34-e411-4409-b141-5c3eca13c1ed.png")!,
NSURL(string: "http://ocr68xaax.bkt.clouddn.com/images/product/74069900-23d3-4795-9f03-a4000649e1ed.png")!,
NSURL(string: "http://ocr68xaax.bkt.clouddn.com/images/operator/6fd532d0-18c4-44ed-b492-d50d8991ec03.png")!,
NSURL(string: "https://upload.wikimedia.org/wikipedia/commons/c/c5/M101_hires_STScI-PRC2006-10a.jpgppp")!
]
func arrayWithImages(slider: EYImageSlider) -> [NSURL] {
return images
}
Specify the image content mode
func contentModeForImage(imageIndex: Int, inSlider: EYImageSlider) -> UIViewContentMode {
return .ScaleAspectFit
}
Specify the caption for each image [Optional]
captions = [
"Joystick",
"SpiderX",
"Avatar",
"Not found"
]
func captionForImageAtIndex(imageIndex: Int, inSlider: EYImageSlider) -> String {
return captions[imageIndex]
}
Callback when image is tapped.
func imageSlider(slider: EYImageSlider, didSelectImageAtIndex index: Int) {
UIApplication.sharedApplication().openURL(images[index])
}
For more example, please checkout EYImageSliderDemo
project for swift, and EYImageSliderDemo-OC
for Objective-C.
imageSlider = EYImageSlider()
imageSlider.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height - 44)
imageSlider.dataSource = self
imageSlider.delegate = self
imageSlider.captionTextColor = UIColor.whiteColor()
view.addSubview(imageSlider)
That is it. Easy? Happy coding…