ImageSelector 0.1.2

ImageSelector 0.1.2

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jan 2019
SPMSupports SPM

Maintained by OverSwift, Hellen Soloviy.



 
Depends on:
PermissionsService/Camera>= 0
PermissionsService/Gallery>= 0
 

  • By
  • overswift

ImageSelector

CI Status Version Swift Version iOS Platform License By

The simplest way to work with camera & photo library.

  1. Features
  2. Requirements
  3. Installation
  4. How To Use
  5. Customizing
  6. Example Project
  7. Author
  8. License

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"

❗️ This pod have a dependency to ios-permissions-service framework so it will be installed too. You can read about it here.

How To Use

  1. Configure your project for chosen permission type: add a specific key with purpose string to your .plist file.

  2. 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
  1. 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.

  1. Call showImageSources() method
     imageController.showImageSources()
  1. Build. Run. Be happy! 🎉

Customizing

  • You can add Delete option to action sheet wich presenting to the user via showImageSources method. By default, this method contains a false parameter for the delete option, so you can change it to true.
     imageController.showImageSources(true)
  • If you don't want to show actions sheet to the user, you can simply call pickFromGallery() or pickFromCamera() 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 of ImagePickerController.

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

❗️ For more details or if you have some problems you can check Example project.

How to do it?

  1. Clone the repo.
  2. run pod install from the Example directory
  3. Enjoy! 🎉

Author

Lemberg Solutions

iOS Platform

Sergiy Loza, [email protected]

License

ImageSelector is available under the MTI license. See the LICENSE file for more info.