TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Feb 2016 |
SPMSupports SPM | ✗ |
Maintained by Benjamin Hendricks.
A customizable photo picker view controller for iOS – Swift
Add pod 'CBPhotoPicker'
to your Podfile
Run pod install
At the top of the file where you’d like to use CBPhotoPicker
, insert import CBPhotoPicker
Create a photo picker by instantiating a photo picker view controller.
In code, that would be:
let photoPicker = CBPhotoPickerViewController(frame: view.frame, aspectRatio: 1)
photoPicker.delegate = self
self.presentViewController(photoPicker, animated: true, completion: {})
This will present a photo picker with an aspect ratio of the picked image as 1:1.
As of right now, if you don’t provide you’re own dismissal strategy, triple tap will dismiss the photo picker
The class presenting the above photo picker needs to conforming to CBPhotoPickerViewControllerDelegate
protocol, which involves two methods. The handleCancel()
method right now doesn’t do anything, but the handleSuccess
method will properly give you the result image when the photo picker is dismissed.
Added a push behavior to bring all images that go off screen back into the view. I think there is a bug where if it’s zoomed in you lose the zoom state, but otherwise it works!
BREAKING CHANGES – you now need to add 2 parameters to your calls to initialize a CBPhotoPickerViewController
.
let photoPicker = CBPhotoPickerViewController(frame: view.frame, aspectRatio: 1, placeholder: nil, cbPhotoPickerStyle: style)
photoPicker.delegate = self
self.presentViewController(photoPicker, animated: true, completion: {})
The placeholder image is what is shown to your users before they choose an image. The style parameter is required, but a default style is provided. To get the style, just do:
let style = CBPhotoPickerStyle.defaultStyle()
Alternatively, if you want to customize the appearance of the photo picker (so far we’ve only opened up the tintColor for text/buttons, and the selectionColor of the image cells)
let style = CBPhotoPickerStyle.customStyle(UIColor.blueColor(), tintColor: UIColor.whiteColor())
Change this around to make it look however you want it to look!
Fixed the constraints breaking in the background, no more annoying spam log messages!
Made some variables public to be visible to use the photo picker in storyboards.
Made a lot of changes:
UPDATE FROM 0.14 to THIS VERSION. 0.15-0.19 are junk, and do not work because of a failed importing of DZNEmptyDataSet v0.1.21 will include an empty state of my own creation.