Your customizable asset picker.
iOS 10.0+ Xcode 10.1+ Swift 4.2+
- Load camera rolls and others albums
- Customize cells
- Customize style and localization
- Custom header
- Photo on the cloud
- Permissions handling
- Other asset ( LivePhoto, Video, Gif, .. )
- Background downloading
- Selection counter ( badge ? )
letphotoPicker=MosaiqueAssetPickerViewController()
photoPicker.pickerDelegate =selfpresent(photoPicker, animated:true, completion:nil)letcellRegistrator=AssetPickerCellRegistrator()
cellRegistrator.register(cellClass:Demo2AssetCell.self, forCellType:.asset)
cellRegistrator.register(cellClass:Demo2AssetCollectionCell.self, forCellType:.assetCollection)letphotoPicker=MosaiqueAssetPickerViewController().setCellRegistrator(cellRegistrator)
photoPicker.pickerDelegate =selfpresent(photoPicker, animated:true, completion:nil)letassetNib=UINib(nibName:String(describing:Demo3AssetNib.self), bundle:nil)letassetCollectionNib=UINib(nibName:String(describing:Demo3AssetCollectionNib.self), bundle:nil)letcellRegistrator=AssetPickerCellRegistrator()
cellRegistrator.register(nib: assetNib, forCellType:.asset)
cellRegistrator.register(nib: assetCollectionNib, forCellType:.assetCollection)letphotoPicker=MosaiqueAssetPickerViewController().setCellRegistrator(cellRegistrator)
photoPicker.pickerDelegate =selfpresent(photoPicker, animated:true, completion:nil)letheaderView=UIView()
headerView.backgroundColor =.orange
headerView.translatesAutoresizingMaskIntoConstraints =false
headerView.heightAnchor.constraint(equalToConstant:120).isActive =trueletphotoPicker=MosaiqueAssetPickerViewController().setHeaderView(headerView, isHeaderFloating:true)
photoPicker.pickerDelegate =selfpresent(photoPicker, animated:true, completion:nil)func setSelectionMode(_ selectionMode:SelectionMode)func setSelectionMode(_ selectionColor:UIColor)func setSelectionColor(_ tintColor:UIColor)func setNumberOfItemsPerRow(_ numberOfItemsPerRow:Int)func setHeaderView(_ headerView:UIView, isHeaderFloating:Bool)func setCellRegistrator(_ cellRegistrator:AssetPickerCellRegistrator)func setMediaTypes(_ supportOnlyMediaType:[PHAssetMediaType])func disableOnLibraryScrollAnimation()func localize(_ localize:LocalizedStrings)
public enum SelectionMode {
case single
case multiple(limit: Int)}publicstructLocalizedStrings{publicvardone:String="Done"publicvarnext:String="Next"publicvardismiss:String="Dismiss"publicvarcollections:String="Collections"publicvarchangePermissions:String="Change your Photo Library permissions"}AssetFuture can be used to dismiss the view controller once the asset is selected but before the asset is ready/downloaded. It can be optained through the delegate:
func photoPicker(_ pickerController: UIViewController, didPickAssets assets: [AssetFuture])
You can retreive asynchronously a thumbnail with onThumbnailCompletion: ((Result<UIImage, NSError>) -> Void)?
And the final image with finalImageResult: Result<UIImage, NSError>?
As long as the AssetFuture is retained by you or the MosaiqueAssetPickerViewController, the asset will be fetched, using the network if needed, even if the app enters background. The fetch request is cancelled on release.
The new iOS version introduce lots of improvements on the traditional image picker. You can default to it if the user runs iOS 14 by using the new API:
MosaiqueAssetPickerPresenter.controller(delegate: self)
pod 'MosaiqueAssetsPicker'
dependencies: [
.package(url: "https://github.com/eure/AssetsPicker.git", .upToNextMajor(from: "1.3.0"))
]
- Pairs Engage
Feel free to contribute. You can format your code using swiftformat:
swiftformat .
Install it with
brew install swiftformat
- Muukii muukii.app@gmail.com
- Aymen Rebouh aymenmse@gmail.com
- Antoine Marandon antoine@marandon.fr
AssetsPicker is released under the MIT license.
