Giter VIP home page Giter VIP logo

dkimagepickercontroller's Introduction

DKImagePickerController

Build Status Version Status license MIT

Update for Xcode 7 with Swift 2.0

Description

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 8.0+
  • 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

The 3.x aren't supported before iOS 8. If you want to support iOS 7, you can look at the 2.4.3 branch that uses ALAssetsLibrary instead of using Photos.

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.didSelectAssets = { (assets: [DKAsset]) in
    print("didSelectAssets")
    print(assets)
}

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

Customizing

/// Forces selection 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

/// Set the defaultAssetGroup to specify which album is the default asset group.
public var defaultAssetGroup: PHAssetCollectionSubtype?

/// The types of PHAssetCollection to display in the picker.
public var assetGroupTypes: [PHAssetCollectionSubtype] = [
    .SmartAlbumUserLibrary,
    .SmartAlbumFavorites,
    .AlbumRegular
    ]

/// Set the showsEmptyAlbums to specify whether or not the empty albums is shown in the picker.
public var showsEmptyAlbums = true

/// 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

/// If YES, and the requested image is not stored on the local device, the Picker downloads the image from iCloud.
public var autoDownloadWhenAssetIsInCloud = true

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

/// The callback block is executed when user pressed the select button.
public var didSelectAssets: ((assets: [DKAsset]) -> 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()
]

Hides camera

pickerController.sourceType = .Photo

Quickly take a picture

pickerController.sourceType = .Camera

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 DKImageManager and DKImagePickerController to your project

  • Importing it into your Objective-C file:

    #import "YourProductModuleName-Swift.h"

then you can:

DKImagePickerController *pickerController = [DKImagePickerController new];
pickerController.assetType = DKImagePickerControllerAssetTypeAllAssets;
pickerController.showsCancelButton = NO;
pickerController.showsEmptyAlbums = YES;
pickerController.allowMultipleTypes = YES;
pickerController.defaultSelectedAssets = @[];
//  pickerController.sourceType         // unavailable
//  pickerController.assetGroupTypes    // unavailable
//  pickerController.defaultAssetGroup  // unavailable

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

Change Log

In 3.0.4, I've updated the fetchImage... interface:
the completeBlock: (image: UIImage?) -> Void was changed to completeBlock: (image: UIImage?, info: [NSObject : AnyObject]?) -> Void so you need to change:

asset.fetchImageWithSize(size, completeBlock: { image in
    // ...
})

to:

asset.fetchImageWithSize(size, completeBlock: { image, info in
    // ...
})

3.0.4 (2015-12-28)

Full Changelog

Closed issues:

  • Cannot use DKAsset.fetchImageWithSize with iCloud photos (Perhaps?) #58

Merged pull requests:

  • Improved performance when getting list of images.

  • Added support for iCloud.

  • Updated fetchImage... interface that added handling for info.

3.0.3 (2015-12-25)

Full Changelog

Merged pull requests:

  • Fixed an issue that may cause full screen image is incorrect.

More logs...

Special Thanks

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

License

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

dkimagepickercontroller's People

Contributors

scottdelly avatar zhangao0086 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.