Skip to content

jmkr/SimpleAssetPicker

Repository files navigation

SimpleAssetPicker

Version CocoaPods compatible

SimpleAssetPicker is a modern Swift library that lets users browse and select media assets from their Photo library. It is built using the Photos framework and is highly customizable to match the theme of your app.

Installation

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

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

    self.simpleAssetPickerViewController = SimpleAssetPickerViewController()
    self.simpleAssetPickerViewController?.delegate = self
    self.view.addSubview(self.simpleAssetPickerViewController!.view)
}

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.