The simplest way to work with camera & photo library.
- Automatic permission request
- Permissions error handling
- ActionsSheet creating, presenting and handling
- Simple and fast implementing
- Customising opportunity
- Localizing opportunity for dialogue
- iOS 9.0+
- Swift 3.0+
- Xcode 8.0+
ImageSelector is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "ImageSelector"
❗ This pod have a dependency to ios-permissions-service framework so it will be installed too. You can read about it here.
-
Configure your project for chosen permission type: add a specific key with purpose string to your .plist file.
-
Implement
ImageSelector
protocol 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
ImagePickerController
custom type
private lazy var imageController: ImagePickerController = {
let picker = ImagePickerController(imageSelector: self)
return picker
}()
❗ You can do it not
lazy
, but you should always create it like global variable and never like local.
- Call
showImageSources()
method
imageController.showImageSources()
- Build. Run. Be happy! 🎉
- You can add
Delete
option to action sheet wich presenting to the user viashowImageSources
method. By default, this method contains afalse
parameter 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
❗ For more details or if you have some problems you can check Example project.
- Clone the repo.
- run
pod install
from the Example directory - Enjoy! 🎉
Sergiy Loza, sergiy.loza@lemberg.co.uk
ImageSelector is available under the MTI license. See the LICENSE file for more info.