/DKImagePickerController

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

Primary LanguageSwiftMIT LicenseMIT

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.didCancel = { () in
    println("didCancel")
}

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

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

Customizing

/// Forces selction of tapped image immediatly
public var singleSelect = false

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

// The types of ALAssetsGroups to display in the picker
public var assetGroupTypes: UInt32 = ALAssetsGroupAll

/// 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 didSelectAssets: ((assets: [DKAsset]) -> Void)?

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

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

You can easily customize the appearance of navigation bar using the appearance proxy.

UINavigationBar.appearance().titleTextAttributes = [
    NSFontAttributeName : UIFont(name: "Optima-BoldItalic", size: 21)!,
    NSForegroundColorAttributeName : UIColor.redColor()
]

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 setDidSelectAssets:^(NSArray * __nonnull assets) {
    NSLog(@"didSelectAssets");
}];

[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!


You can merge your branch into the develop branch. Any Pull Requests to be welcome!!!

Special Thanks

Thanks for scottdelly's contribution and performance improvement!
Thanks for LucidityDesign's contribution!

License

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