MKImageViewer is used to display images in horizontal scrollview. It is very easy to integrate in your project.
To run the example project, clone the repo, and run pod install
from the Example directory first.
iOS 8 OR greater
MkImageViewer is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'MkImageViewer'
To integrate MKImageViewer, you just need to follow following steps:
- Import MKImageViewer on top of your file.
import MkImageViewer
- Use following lines of code to display images:
let controller:MKImageViewController = MKImageViewController()
controller.images = [MKImage(url: URL(string: "https://images.pexels.com/photos/34950/pexels-photo.jpg")),MKImage(url: URL(string: "https://images.pexels.com/photos/459225/pexels-photo-459225.jpeg")),MKImage(url: URL(string: "https://i.ytimg.com/vi/c2NmyoXBXmE/maxresdefault.jpg")),MKImage(url: URL(string: "https://www.nmfnewsonline.com/upload/news/lifestyle/Nmf2adb21_02_01_slide_nature.jpg")),MKImage(image: UIImage.init(named: "water"))];
controller.delegate = self;
controller.placeholderImage = UIImage(named: "Placeholder")
self.navigationController?.pushViewController(controller, animated: true)
In above example you can see that this library provide you options for passing Images object Via URL OR direct UIImage Object.
You can set delegate if you want to handle pagination. Delegate method will call on scroll of every image. You can fetch new images record from API and can append to image viewer as given below:
func willDisplayImage(index:Int) -> Void{
// fetch new image as per your requirement and append as given below:
controller.appendImages([List of MKImage object])
}}
Library is designed for portrait mode only.
mohit5189, [email protected]
MkImageViewer is available under the MIT license. See the LICENSE file for more info.