paterson / DKImagePickerController

New version! It's A Facebook style Image Picker Controller by Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DKImagePickerController

Build Status Version Status license MIT

Update for Xcode 7 with Swift 2.0

Description

New version! It's A Facebook style Image Picker Controller by Swift. It uses DKCamera instead of UIImagePickerController since the latter cannot be Integrated into another container, and it will raise a warning Snapshotting ... or snapshot after screen updates. in iOS 8.

Requirements

  • iOS 7.1+
  • ARC

Installation

iOS 8 and newer

DKImagePickerController is available on Cocoapods. Simply add the following line to your podfile:

# For latest release in cocoapods
pod 'DKImagePickerController'

iOS 7.x

To use Swift libraries on apps that support iOS 7, you must manually copy the files into your application project. CocoaPods only supports Swift on OS X 10.9 and newer, and iOS 8 and newer.

Getting Started

Initialization and presentation

let pickerController = DKImagePickerController()

pickerController.didCancelled = { () in
    println("didCancelled")
}

pickerController.didSelectedAssets = { [unowned self] (assets: [DKAsset]) in
    println("didSelectedAssets")
    println(assets)
}

self.presentViewController(pickerController, animated: true) {}

Customizing

/// The maximum count of assets which the user will be able to select.
public var maxSelectableCount = 999

/// The type of picker interface to be displayed by the controller.
public var assetType = DKImagePickerControllerAssetType.allAssets

/// If sourceType is Camera will cause the assetType & maxSelectableCount & allowMultipleTypes & defaultSelectedAssets to be ignored.
public var sourceType: DKImagePickerControllerSourceType = .Camera | .Photo

/// Whether allows to select photos and videos at the same time.
public var allowMultipleTypes = true

/// The callback block is executed when user pressed the select button.
public var didSelectedAssets: ((assets: [DKAsset]) -> Void)?

/// The callback block is executed when user pressed the cancel button.
public var didCancelled: (() -> Void)?

/// It will have selected the specific assets.
public var defaultSelectedAssets: [DKAsset]?

Quickly take a picture

pickerController.sourceType = .Camera

Hides camera

pickerController.sourceType = .Photo

How to use in Objective-C

If you use CocoaPods

  • Adding the following two lines into your Podfile:

    pod 'DKImagePickerController'
    use_frameworks!
  • Importing it into your Objective-C file:

    #import <DKImagePickerController/DKImagePickerController-Swift.h>

If you use it directly in your project

See also:Swift and Objective-C in the Same Project

  • Drag and drop the DKCamera and DKImagePickerController to your project

  • Importing it into your Objective-C file:

    #import "YourProductModuleName-Swift.h"

then you can:

DKImagePickerController *imagePickerController = [DKImagePickerController new];
[imagePickerController setDidSelectedAssets:^(NSArray * __nonnull assets) {
    NSLog(@"didSelected");
}];

[self presentViewController:imagePickerController animated:YES completion:nil];

Localization

It has been supported languages so far:

  • en.lproj
  • zh-Hans.lproj

If you want to add new language, pull request or issue!

Soon to do

  • Simple photo browser.

Any pull requests to be welcome!!!

License

DKImagePickerController is released under the MIT license. See LICENSE for details.

About

New version! It's A Facebook style Image Picker Controller by Swift.

License:MIT License


Languages

Language:Swift 98.7%Language:Ruby 1.3%