Skip to content

jmkr/SimpleAssetPicker

Repository files navigation

SimpleAssetPicker

Version Build Status CocoaPods compatible

SimpleAssetPicker is a modern Swift library that encapsulates common Photo Library usage and lets you quickly add functionality to your app to enable browsing and selection of media assets. It is built using the Photos framework and is highly customizable to match the theme of your app.

Demo Gif

Installation

use_frameworks!
platform :ios, '8.0'
pod 'SimpleAssetPicker'

Example

There's a sample project in the Example folder.

Using in your project

In any view controller you can start by adding:

import SimpleAssetPicker

override func viewDidLoad() {
    super.viewDidLoad()

    SimpleAssetPickerConfig.sharedConfig().pickerMediaType = .video
    SimpleAssetPickerConfig.sharedConfig().maxMediaSelectionAmount = 1

    let simpleAssetPickerViewController = SimpleAssetPickerViewController()
    simpleAssetPickerViewController.delegate = self
    self.view.addSubview(simpleAssetPickerViewController.view)
    simpleAssetPickerViewController.didMove(toParentViewController: self)
}

SimpleAssetPickerDelegate

Use these protocol methods to handle events sent from SimpleAssetPicker:

func didCancel(picker: SimpleAssetPickerViewController)
func didSatisfyMediaRequirements(picker: SimpleAssetPickerViewController, assets: [PHAsset]?)
func didBreakMediaRequirements(picker: SimpleAssetPickerViewController)

Customization

SimpleAssetPickerConfig contains several variables which you can change to modify the behavior and appearance of your asset picker. You can access and modify these variables through the shared instance:

SimpleAssetPickerConfig.sharedConfig().maxMediaSelectionAmount = 1

Some customization options include:

// Asset selection constraints
public var minMediaSelectionAmount: Int?
public var maxMediaSelectionAmount: Int?

// Appearance config variables
public var numberOfItemsPerRow: Int?
public var pickerMediaType: SimpleAssetPickerMediaType?
public var assetSelectedImageName: String?
public var cellSize: CGSize?
public var collectionViewEdgeInsets: UIEdgeInsets?
public var verticalCellSpacing: Float?

Thank you

Pull requests, comments, and suggestions are always welcome.

Distributed with the MIT license. Enjoy.