ImageSelector
The simplest way to work with camera & photo library.
Features
- Automatic permission request
- Permissions error handling
- ActionsSheet creating, presenting and handling
- Simple and fast implementing
- Customising opportunity
- Localizing opportunity for dialogue
Requirements
- iOS 9.0+
- Swift 3.0+
- Xcode 8.0+
Installation
ImageSelector is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "ImageSelector"How To Use
-
Configure your project for chosen permission type: add a specific key with purpose string to your .plist file.
-
Implement
ImageSelectorprotocol in your class with all methods.
| Name | Description |
|---|---|
presentingController |
Should return current view controller, for example, self |
imageSelected(_:) |
Will return you selected image or photo from camera |
imageSelectionCanceled() |
Do something when user cancel |
imageDeleted() |
User choose to delete option in presented dialogue |
editingAllowed() |
Allow or disable edit option |
- Create object of type
ImagePickerControllercustom type
private lazy var imageController: ImagePickerController = {
let picker = ImagePickerController(imageSelector: self)
return picker
}()
❗️ You can do it notlazy, but you should always create it like global variable and never like local.
- Call
showImageSources()method
imageController.showImageSources()- Build. Run. Be happy!
🎉
Customizing
- You can add
Deleteoption to action sheet wich presenting to the user viashowImageSourcesmethod. By default, this method contains afalseparameter for the delete option, so you can change it totrue.
imageController.showImageSources(true)-
If you don't want to show actions sheet to the user, you can simply call
pickFromGallery()orpickFromCamera()to show image picker. -
You can localise action sheet or give it your custom messages by creating custom
ImagePickerControllerConfiguration. After it, you need to put into the init method ofImagePickerController.
If you don't create custom configuration default value will be used.
let configuration = ImagePickerControllerConfiguration()
configuration.actionSheetTitle = "Select photo"
configuration.actionSheetMessage = "Select image from proposed sources"
configuration.cameraActionTitle = "Take a photo"
configuration.galleryActionTitle = "Chose a photo"
configuration.removeActionTitle = "Remove a photo"
configuration.camera = .front
let picker = ImagePickerController(imageSelector: self, configuration())By adding custom configuration you can change default camera source too.
configuration.camera = .front
Example Project
How to do it?
- Clone the repo.
- run
pod installfrom the Example directory - Enjoy!
🎉
Author
Lemberg Solutions
Sergiy Loza, [email protected]
License
ImageSelector is available under the MTI license. See the LICENSE file for more info.
