Home

Awesome

<h1 align="center">SKPhotoBrowser</h1> <H4 align="center"> Simple PhotoBrowser/Viewer inspired by facebook, twitter photo browsers written by swift </H4> <p align="center"> <a href="https://developer.apple.com/swift"> <img alt="Swift5" src="https://img.shields.io/badge/language-swift5.4-orange.svg?style=flat" /> </a> <a href="http://cocoadocs.org/docsets/SKPhotoBrowser"> <img src="https://img.shields.io/cocoapods/v/SKPhotoBrowser.svg?style=flat" /> </a> <a href="https://github.com/Carthage/Carthage"> <img alt="Build Status" src="https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat" /> </a> <a href="https://developer.apple.com/swift/"> <img alt="Platform" src="https://img.shields.io/badge/platform-iOS-green.svg" /></a> <a href=""> <img alt="Contributors" src="https://img.shields.io/badge/all_contributors-66-orange.svg?style=flat-square" /></a> </p>

features

Table/CollectionView sampleButton tap samplegif sample
samplesamplesample

Requirements

    - iOS 9.0+
    - Swift 2.0+
    - ARC

Version vs Swift version.

    Below is a table that shows which version of SKPhotoBrowser you should use for your Swift version.
Swift versionSKPhotoBrowser version
5.0>= 6.1.0
4.2>= 6.0.0
4.1>= 5.0.0
3.2>= 4.0.0
2.32.0.4 - 3.1.4
2.2<= 2.0.3

Installation

CocoaPods

available on CocoaPods. Just add the following to your project Podfile:

pod 'SKPhotoBrowser'
use_frameworks!

Carthage

To integrate into your Xcode project using Carthage, specify it in your Cartfile:

github "suzuki-0000/SKPhotoBrowser"

Info.plist

If you want to use share image feature, it includes save image into galery, so you should specify a permission into your Info.plist (if you haven't done it yet).

<key>NSPhotoLibraryAddUsageDescription</key>
<string>Used to save images into your galery</string>

Swift Package Manager

Available in Swift Package Manager. Use the repository URL in Xcode

Usage

See the code snippet below for an example of how to implement, or see the example project.

from UIImages:

// 1. create SKPhoto Array from UIImage
var images = [SKPhoto]()
let photo = SKPhoto.photoWithImage(UIImage())// add some UIImage
images.append(photo)

// 2. create PhotoBrowser Instance, and present from your viewController.
let browser = SKPhotoBrowser(photos: images)
browser.initializePageIndex(0)
present(browser, animated: true, completion: {})

from URLs:

// 1. create URL Array
var images = [SKPhoto]()
let photo = SKPhoto.photoWithImageURL("https://placehold.jp/150x150.png")
photo.shouldCachePhotoURLImage = false // you can use image cache by true(NSCache)
images.append(photo)

// 2. create PhotoBrowser Instance, and present.
let browser = SKPhotoBrowser(photos: images)
browser.initializePageIndex(0)
present(browser, animated: true, completion: {})

from local files:

// 1. create images from local files
var images = [SKLocalPhoto]()
let photo = SKLocalPhoto.photoWithImageURL("..some_local_path/150x150.png")
images.append(photo)

// 2. create PhotoBrowser Instance, and present.
let browser = SKPhotoBrowser(photos: images)
browser.initializePageIndex(0)
present(browser, animated: true, completion: {})

If you want to use zooming effect from an existing view, use another initializer:

// e.g.: some tableView or collectionView.
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
   let cell = collectionView.cellForItemAtIndexPath(indexPath)
   let originImage = cell.exampleImageView.image // some image for baseImage

   let browser = SKPhotoBrowser(originImage: originImage ?? UIImage(), photos: images, animatedFromView: cell)
   browser.initializePageIndex(indexPath.row)
   present(browser, animated: true, completion: {})
}

Custom

Toolbar

You can customize Toolbar via SKPhotoBrowserOptions.

SKPhotoBrowserOptions.displayToolbar = false                              // all tool bar will be hidden
SKPhotoBrowserOptions.displayCounterLabel = false                         // counter label will be hidden
SKPhotoBrowserOptions.displayBackAndForwardButton = false                 // back / forward button will be hidden
SKPhotoBrowserOptions.displayAction = false                               // action button will be hidden
SKPhotoBrowserOptions.displayHorizontalScrollIndicator = false            // horizontal scroll bar will be hidden
SKPhotoBrowserOptions.displayVerticalScrollIndicator = false              // vertical scroll bar will be hidden
let browser = SKPhotoBrowser(originImage: originImage, photos: images, animatedFromView: cell)

Colors

You can customize text, icon and background colors via SKPhotoBrowserOptions or SKToolbarOptions

SKPhotoBrowserOptions.backgroundColor = UIColor.whiteColor()               // browser view will be white
SKPhotoBrowserOptions.textAndIconColor = UIColor.blackColor()              // text and icons will be black
SKToolbarOptions.textShadowColor = UIColor.clearColor()                    // shadow of toolbar text will be removed
SKToolbarOptions.font = UIFont(name: "Futura", size: 16.0)                 // font of toolbar will be 'Futura'

Images

You can customize the padding of displayed images via SKPhotoBrowserOptions

SKPhotoBrowserOptions.imagePaddingX = 50                                   // image padding left and right will be 25
SKPhotoBrowserOptions.imagePaddingY = 50                                   // image padding top and bottom will be 25

Statusbar

You can customize the visibility of the Statusbar in browser view via SKPhotoBrowserOptions

SKPhotoBrowserOptions.displayStatusbar = false                             // status bar will be hidden

Close And Delete Buttons

That how you can customize close and delete buttons

SKPhotoBrowserOptions.displayDeleteButton = true                           // delete button will be shown
SKPhotoBrowserOptions.swapCloseAndDeleteButtons = true                     // now close button located on right side of screen and delete button is on left side
SKPhotoBrowserOptions.closeAndDeleteButtonPadding = 20                     // set offset from top and from nearest screen edge of close button and delete button

Screenshot Protection

You can protect your image from taking screenshot via SKPhotoBrowserOptions Only working on the device, not on simulator

SKPhotoBrowserOptions.protectScreenshot = true                             // image will be hidden after taking screenshot

Custom Cache From Web URL

You can use SKCacheable protocol if others are adaptable. (SKImageCacheable or SKRequestResponseCacheable)

e.g. SDWebImage

// 1. create custom cache, implement in accordance with the protocol
class CustomImageCache: SKImageCacheable { var cache: SDImageCache }

// 2. replace SKCache instance with custom cache
SKCache.sharedCache.imageCache = CustomImageCache()

CustomButton Image

Close, Delete buttons are able to change image and frame.

browser.updateCloseButton(UIImage())
browser.updateUpdateButton(UIImage())

Delete Photo

You can delete your photo for your own handling. detect button tap from removePhoto delegate function.

Photo Captions

Photo captions can be displayed simply bottom of PhotoBrowser. by setting the caption property on specific photos:

let photo = SKPhoto.photoWithImage(UIImage())
photo.caption = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."

SwipeGesture

vertical swipe can enable/disable:

SKPhotoBrowserOptions.disableVerticalSwipe = true

Delegate

There's some trigger point you can handle using delegate. those are optional. See SKPhotoBrowserDelegate for more details.

let browser = SKPhotoBrowser(originImage: originImage, photos: images, animatedFromView: cell)
browser.delegate = self

// MARK: - SKPhotoBrowserDelegate
func didShowPhotoAtIndex(_ index: Int) {
// when photo will be shown
}

func willDismissAtPageIndex(_ index: Int) {
// when PhotoBrowser will be dismissed
}

func didDismissAtPageIndex(_ index: Int) {
// when PhotoBrowser did dismissed
}

Options

You can access via SKPhotoBrowserOptions, which can use for browser control. See SKPhotoBrowserOptions for more details.

SKPhotoBrowserOptions.enableZoomBlackArea    = true  // default true
SKPhotoBrowserOptions.enableSingleTapDismiss = true  // default false

Photos from

License

available under the MIT license. See the LICENSE file for more info.

Contributors

Thanks goes to these wonderful people (emoji key):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- prettier-ignore-start --> <!-- markdownlint-disable --> <table> <tr> <td align="center"><a href="https://p36348.github.io/"><img src="https://avatars.githubusercontent.com/u/6042275?v=4?s=20" width="20px;" alt=""/><br /><sub><b>Oreo Chen</b></sub></a><br /><a href="https://github.com/suzuki-0000/SKPhotoBrowser/commits?author=p36348" title="Code">πŸ’»</a></td> </tr> </table> <!-- markdownlint-restore --> <!-- prettier-ignore-end --> <!-- ALL-CONTRIBUTORS-LIST:END --> <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- prettier-ignore -->
<img src="https://avatars1.githubusercontent.com/u/12511909?v=4" width="60px;"/><br /><sub><b>Alexander Khitev</b></sub><br />πŸ’»<img src="https://avatars2.githubusercontent.com/u/1032307?v=4" width="60px;"/><br /><sub><b>K Rummler</b></sub><br />πŸ’»<img src="https://avatars2.githubusercontent.com/u/198395?v=4" width="60px;"/><br /><sub><b>Mads Bjerre</b></sub><br />πŸ’»<img src="https://avatars3.githubusercontent.com/u/4025839?v=4" width="60px;"/><br /><sub><b>Meng Ye</b></sub><br />πŸ’»<img src="https://avatars2.githubusercontent.com/u/351683?v=4" width="60px;"/><br /><sub><b>_ant_one</b></sub><br />πŸ’»<img src="https://avatars0.githubusercontent.com/u/13894518?v=4" width="60px;"/><br /><sub><b>Tim Roesner</b></sub><br />πŸ’»<img src="https://avatars0.githubusercontent.com/u/1303682?v=4" width="60px;"/><br /><sub><b>θƒ₯ε†₯</b></sub><br />πŸ’»
<img src="https://avatars3.githubusercontent.com/u/371957?v=4" width="60px;"/><br /><sub><b>Kevin Wolkober</b></sub><br />πŸ’»<img src="https://avatars2.githubusercontent.com/u/110283?v=4" width="60px;"/><br /><sub><b>PJ Gray</b></sub><br />πŸ’»<img src="https://avatars1.githubusercontent.com/u/4082752?v=4" width="60px;"/><br /><sub><b>ghysrc</b></sub><br />πŸ’»<img src="https://avatars1.githubusercontent.com/u/5204614?v=4" width="60px;"/><br /><sub><b>Josef DoleΕΎal</b></sub><br />πŸ’»<img src="https://avatars1.githubusercontent.com/u/189020?v=4" width="60px;"/><br /><sub><b>Mark Goody</b></sub><br />πŸ’»<img src="https://avatars2.githubusercontent.com/u/1270537?v=4" width="60px;"/><br /><sub><b>Philippe Riegert</b></sub><br />πŸ’»<img src="https://avatars2.githubusercontent.com/u/399560?v=4" width="60px;"/><br /><sub><b>Bryan Irace</b></sub><br />πŸ’»
<img src="https://avatars1.githubusercontent.com/u/12068299?v=4" width="60px;"/><br /><sub><b>dirtmelon</b></sub><br />πŸ’»<img src="https://avatars0.githubusercontent.com/u/103670?v=4" width="60px;"/><br /><sub><b>Heberti Almeida</b></sub><br />πŸ’»<img src="https://avatars2.githubusercontent.com/u/501784?v=4" width="60px;"/><br /><sub><b>Felix Weiss</b></sub><br />πŸ’»<img src="https://avatars1.githubusercontent.com/u/8625327?v=4" width="60px;"/><br /><sub><b>.Some</b></sub><br />πŸ’»<img src="https://avatars3.githubusercontent.com/u/4017312?v=4" width="60px;"/><br /><sub><b>Onur Var</b></sub><br />πŸ’»<img src="https://avatars3.githubusercontent.com/u/1316152?v=4" width="60px;"/><br /><sub><b>Andrew Barba</b></sub><br />πŸ’»
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the all-contributors specification. Contributions of any kind welcome!