If you prefer to receive selected photos in type of PHAsset instead of UIImage then don’t forget to set the shouldReturnAsset to true and implement the corresponding delegation method.
Implement FMImageEditorViewControllerDelegate protocol to handle ouput image
mediaTypes An array that indicates the media types to be accessed by the picker controller. Type: [FMMediaType] Default: [.image, .video]
selectMode Photo selection mode that can be in single or multiple mode. Type: : FMSelectMode Default is multiple
maxImage The maximum number of images can be selected.
Type: Int Default: 10
maxVideo The maximum number of videos can be selected. Type: Int Default is 10
availableFilters Filter options that are used in editor. Set this parameter to nil to make the filter menu be unavailable in the editor
FMPhotoEditor provides some default filters that will be fit to you. Type: [FMFilterable]? Default: all filters are provided by FMPhotoPicker.
availableCrops Crop options that is used in editor. Set this parameter to nil to make the cropping menu be unavailable in the editor
FMPhotoEditor provides some default crops that will be fit to you. Type: [FMCroppable]?
Default: all crops provided by FMPhotoPicker.
You are not allowed to use the editor without giving it at least one crop option or one filter option
useCropFirst An option that indicates whether the crop menu should be selected by default in the FMImageEditorViewController. Type: Bool Default: false
alertController An alert controller to show the confirmation view to an user with 2 options: Ok or Cancel. Type: FMAlertable Default: FMAlert
shouldReturnAsset Whether you want FMPhotoPicker returns PHAsset instead of UIImage.
FMPhotoPicker chooses a proper delegation method to be invoked when user finishes picking based on this configuration
Type: Bool
Default: false
forceCropEnabled A bool value that indicates whether force mode is enabled. If true is set, only the first crop in the availableCrops is used in the editor. And that crop’s ration becomes force crop ratio. Type: FMAlertable Default: false
eclipsePreviewEnabled A bool value that indicates whether the preview of image should be displayed in rounded image. Type: Bool
Default: false
strings A dictionary that allows you to customize language for your app. For details, see FMPhotoPickerConfig.swift Type: Dictionary
Customization
Custom filter
You can freely create your own filter by implementing the FMFilterable protocol.
Be careful that the filterName is used to determine whether the two filters are the same. Make sure that your filter’s names are not duplicated, especially with the default filters that you want to use.
Custom cropping
Similar as filter function, FMPhotoPicker provides the capability to use your own cropping by implementing the FMCroppable protocol.
The func name(strings: [String: String]) -> String will receive the strings configuration from configuration object.
It allows you customize the cropping while keeping all your language setting in only one place.
The name() method is also used as identifier for the cropping. Thus, make sure you do not have any duplicate of the cropping name.
Custom alert view controller
You can use your own view style for the confirmation view by implementing the FMAlertable protocol.
FMPhotoPicker is a modern, simple and zero-dependency photo picker with an elegant and customizable image editor
Quick demo
Features
Requirements
Installation
SwiftPM
Carthage
Insert the following line in your Carthfile:
and run
carthage update FMPhotoPickerCocoaPods
FMPhotoPicker is now available in CocoaPods
You want to add pod ‘FMPhotoPicker’, ‘~> 1.3.0’ similar to the following to your Podfile:
Then run a
pod installinside your terminal.Usage
Create a configuration object
For details, see Configuration
Picker
From iOS 10, you have to add the
Privacy - Photo Library Usage Descriptioninto your Info.plist file.Editor
Delegation methods
If you prefer to receive selected photos in type of
PHAssetinstead ofUIImagethen don’t forget to set theshouldReturnAssettotrueand implement the corresponding delegation method.Configuration
The configuration supports the following parameters:
mediaTypesselectModemaxImagemaxVideoavailableFiltersavailableCropsuseCropFirstalertControllershouldReturnAssetforceCropEnabledeclipsePreviewEnabledstringsReference
mediaTypesAn array that indicates the media types to be accessed by the picker controller.
Type:
[FMMediaType]Default:
[.image, .video]selectModePhoto selection mode that can be in
singleormultiplemode.Type: :
FMSelectModeDefault is
multiplemaxImageThe maximum number of images can be selected. Type:
IntDefault:
10maxVideoThe maximum number of videos can be selected.
Type:
IntDefault is
10availableFiltersFilter options that are used in editor. Set this parameter to
nilto make the filter menu be unavailable in the editor FMPhotoEditor provides some default filters that will be fit to you.Type:
[FMFilterable]?Default: all filters are provided by FMPhotoPicker.
availableCropsCrop options that is used in editor. Set this parameter to
nilto make the cropping menu be unavailable in the editor FMPhotoEditor provides some default crops that will be fit to you.Type:
[FMCroppable]?Default: all crops provided by FMPhotoPicker.You are not allowed to use the editor without giving it at least one crop option or one filter option
useCropFirstAn option that indicates whether the crop menu should be selected by default in the
FMImageEditorViewController.Type:
BoolDefault:
falsealertControllerAn alert controller to show the confirmation view to an user with 2 options: Ok or Cancel.
Type:
FMAlertableDefault:
FMAlertshouldReturnAssetWhether you want FMPhotoPicker returns PHAsset instead of UIImage.
FMPhotoPicker chooses a proper delegation method to be invoked when user finishes picking based on this configuration Type:
BoolDefault:falseforceCropEnabledA bool value that indicates whether force mode is enabled.
If
trueis set, only the first crop in theavailableCropsis used in the editor.And that crop’s ration becomes force crop ratio.
Type:
FMAlertableDefault:
falseeclipsePreviewEnabledA bool value that indicates whether the preview of image should be displayed in rounded image.
Type:
BoolDefault:falsestringsA dictionary that allows you to customize language for your app.
For details, see
FMPhotoPickerConfig.swiftType:
DictionaryCustomization
Custom filter
You can freely create your own filter by implementing the
FMFilterableprotocol.Be careful that the filterName is used to determine whether the two filters are the same.
Make sure that your filter’s names are not duplicated, especially with the default filters that you want to use.
Custom cropping
Similar as filter function, FMPhotoPicker provides the capability to use your own cropping by implementing the
FMCroppableprotocol.The
func name(strings: [String: String]) -> Stringwill receive the strings configuration from configuration object. It allows you customize the cropping while keeping all your language setting in only one place.The
name()method is also used as identifier for the cropping.Thus, make sure you do not have any duplicate of the cropping name.
Custom alert view controller
You can use your own view style for the confirmation view by implementing the
FMAlertableprotocol.Contact
Follow and contact me on Twitter. If you find an issue, just open a ticket. Pull requests are warmly welcome as well.
License
FMPhotoPicker is released under the MIT license. See LICENSE for details.