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 ? )
let photoPicker = MosaiqueAssetPickerViewController()
photoPicker.pickerDelegate = self
present(photoPicker, animated: true, completion: nil)
let cellRegistrator = AssetPickerCellRegistrator()
cellRegistrator.register(cellClass: Demo2AssetCell.self, forCellType: .asset)
cellRegistrator.register(cellClass: Demo2AssetCollectionCell.self, forCellType: .assetCollection)
let photoPicker = MosaiqueAssetPickerViewController()
.setCellRegistrator(cellRegistrator)
photoPicker.pickerDelegate = self
present(photoPicker, animated: true, completion: nil)
let assetNib = UINib(nibName: String(describing: Demo3AssetNib.self), bundle: nil)
let assetCollectionNib = UINib(nibName: String(describing: Demo3AssetCollectionNib.self), bundle: nil)
let cellRegistrator = AssetPickerCellRegistrator()
cellRegistrator.register(nib: assetNib, forCellType: .asset)
cellRegistrator.register(nib: assetCollectionNib, forCellType: .assetCollection)
let photoPicker = MosaiqueAssetPickerViewController()
.setCellRegistrator(cellRegistrator)
photoPicker.pickerDelegate = self
present(photoPicker, animated: true, completion: nil)
let headerView = UIView()
headerView.backgroundColor = .orange
headerView.translatesAutoresizingMaskIntoConstraints = false
headerView.heightAnchor.constraint(equalToConstant: 120).isActive = true
let photoPicker = MosaiqueAssetPickerViewController()
.setHeaderView(headerView, isHeaderFloating: true)
photoPicker.pickerDelegate = self
present(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)
}
public struct LocalizedStrings {
public var done: String = "Done"
public var next: String = "Next"
public var dismiss: String = "Dismiss"
public var collections: String = "Collections"
public var changePermissions: 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.