中文 | English
photo/video selector-supports LivePhoto, GIF selection, iCloud resource online download, photo/video editing
- UI Appearance supports light/dark/auto/custom
- Support multiple selection/mixed content selection
- Supported media types:
- Photo
- GIF
- Live Photo
- Video
- Supported local media types:
- Photo
- Video
- GIF
- Live Photo
- Supported network media types:
- Photo
- Video
- Support downloading assets on iCloud
- Support gesture back
- Support sliding selection
- Edit pictures (support animated pictures, network pictures)
- Graffiti
- Sticker
- Text
- Crop
- Mosaic
- Filter
- Edit video (support network video)
- Graffiti
- Stickers (support GIF)
- Text
- Soundtrack (support lyrics and subtitles)
- Crop duration
- Crop Size
- Filter
- Album display mode
- Separate list
- Pop-ups
- Multi-platform support
- iOS
- iPadOS
- Mac Catalyst
- Internationalization support
- 🇨🇳 Chinese, Simplified (zh-Hans)
- 🇬🇧 English (en)
- 🇨🇳 Chinese, traditional (zh-Hant)
- 🇯🇵 Japanese (ja)
- 🇰🇷 Korean (ko)
- 🇹🇭 Thai (th)
- 🇮🇳 Indonesian (id)
- 🇻🇳 Vietnamese (vi)
- 🇷🇺 russian (ru)
- 🇩🇪 german (de)
- 🇫🇷 french (fr)
- 🇸🇦 arabic (ar)
- ✍️ Custom language (custom)
- 🤝 More support... (Pull requests welcome)
- iOS 12.0+
- Xcode 12.5+
- Swift 5.4+
dependencies: [
.package(url: "https://github.com/SilenceLove/HXPhotoPicker.git", .upToNextMajor(from: "4.2.3"))
]
Add this to Podfile, and then update dependency:
iOS 12.0+
pod 'HXPhotoPicker'
/// No Kingfisher
pod `HXPhotoPicker/Lite`
/// Only Picker
pod `HXPhotoPicker/Picker`
pod `HXPhotoPicker/Picker/Lite`
/// Only Editor
pod `HXPhotoPicker/Editor`
pod `HXPhotoPicker/Editor/Lite`
/// Only Camera
pod `HXPhotoPicker/Camera`
/// Does not include location functionality
pod `HXPhotoPicker/Camera/Lite`
iOS 10.0+
pod 'HXPhotoPicker-Lite'
pod 'HXPhotoPicker-Lite/Picker'
pod 'HXPhotoPicker-Lite/Editor'
pod 'HXPhotoPicker-Lite/Camera'
Add these keys to your Info.plist when needed:
Key | Module | Info |
---|---|---|
NSPhotoLibraryUsageDescription | Picker | Allow access to album |
NSPhotoLibraryAddUsageDescription | Picker | Allow to save pictures to album |
PHPhotoLibraryPreventAutomaticLimitedAccessAlert | Picker | Set YES to prevent automatic limited access alert in iOS 14+ (Picker has been adapted with Limited features that can be triggered by the user to enhance the user experience) |
NSCameraUsageDescription | Camera | Allow camera |
NSMicrophoneUsageDescription | Camera | Allow microphone |
import HXPhotoPicker
class ViewController: UIViewController {
func presentPickerController() {
let config = PickerConfiguration()
// Method 1:async/await
let images: [UIImage] = try await Photo.picker(config)
let urls: [URL] = try await Photo.picker(config)
let urlResult: [AssetURLResult] = try await Photo.picker(config)
let assetResult: [AssetResult] = try await Photo.picker(config)
let pickerResult = try await Photo.picker(config)
let images: [UIImage] = try await pickerResult.objects()
let urls: [URL] = try await pickerResult.objects()
let urlResults: [AssetURLResult] = try await pickerResult.objects()
let assetResults: [AssetResult] = try await pickerResult.objects()
// Method 2:
let pickerController = PhotoPickerController(picker: config)
pickerController.pickerDelegate = self
// The array of PhotoAsset objects corresponding to the currently selected asset
pickerController.selectedAssetArray = selectedAssets
// Whether to select the original image
pickerController.isOriginal = isOriginal
present(pickerController, animated: true, completion: nil)
// Method 3:
Photo.picker(
config
) { result, pickerController in
// Select completion callback
// result Select result
// .photoAssets Currently selected data
// .isOriginal Whether the original image is selected
// photoPickerController Corresponding photo selection controller
} cancel: { pickerController in
// Cancelled callback
// photoPickerController Corresponding photo selection controller
}
}
}
extension ViewController: PhotoPickerControllerDelegate {
/// Called after the selection is complete
/// - Parameters:
/// - pickerController: corresponding PhotoPickerController
/// - result: Selected result
/// result.photoAssets Selected asset array
/// result.isOriginal Whether to select the original image
func pickerController(_ pickerController: PhotoPickerController,
didFinishSelection result: PickerResult) {
// async/await
let images: [UIImage] = try await result.objects()
let urls: [URL] = try await result.objects()
let urlResults: [AssetURLResult] = try await result.objects()
let assetResults: [AssetResult] = try await result.objects()
result.getImage { (image, photoAsset, index) in
if let image = image {
print("success", image)
}else {
print("failed")
}
} completionHandler: { (images) in
print(images)
}
}
/// Called when cancel is clicked
/// - Parameter pickerController: Corresponding PhotoPickerController
func pickerController(didCancel pickerController: PhotoPickerController) {
}
}
/// If it is a video, get the cover of the video
// async/await
// compression: if not passed, no compression
let image: UIImage = try await photoAsset.object(compression)
/// Get the `UIImage` of the specified `Size`
/// targetSize: specify imageSize
/// targetMode: crop mode
let image = try await photoAsset.image(targetSize: .init(width: 200, height: 200), targetMode: .fill)
// compressionQuality: Compress parameters, if not passed, no compression
photoAsset.getImage(compressionQuality: compressionQuality) { image in
print(image)
}
// async/await
// compression: if not passed, no compression
let url: URL = try await photoAsset.object(compression)
let urlResult: AssetURLResult = try await photoAsset.object(compression)
let assetResult: AssetResult = try await photoAsset.object(compression)
/// compression: Compress parameters, if not passed, no compression
photoAsset.getURL(compression: compression) { result in
switch result {
case .success(let urlResult):
switch urlResult.mediaType {
case .photo:
case .video:
}
switch urlResult.urlType {
case .local:
case .network:
}
print(urlResult.url)
// Image and video urls contained in LivePhoto
print(urlResult.livePhoto)
case .failure(let error):
print(error)
}
}
/// Get thumbnail
let thumImage = try await photoAsset.requesThumbnailImage()
/// Get preview
let previewImage = try await photoAsset.requestPreviewImage()
/// Get AVAsset
let avAsset = try await photoAsset.requestAVAsset()
/// Get AVPlayerItem
let playerItem = try await photoAsset.requestPlayerItem()
/// Get PHLivePhoto
let livePhoto = try await photoAsset.requestLivePhoto()
Latest updates
Version | Release Date | Xcode | Swift | iOS |
---|---|---|---|---|
v4.2.3 | 2024-08-05 | 15.0.0 | 5.9.0 | 12.0+ |
History record
Version | Release Date | Xcode | Swift | iOS |
---|---|---|---|---|
v4.2.2 | 2024-07-08 | 15.0.0 | 5.9.0 | 12.0+ |
v4.2.1 | 2024-05-18 | 15.0.0 | 5.9.0 | 12.0+ |
v4.2.0 | 2024-04-23 | 15.0.0 | 5.9.0 | 12.0+ |
v4.1.9 | 2024-04-09 | 15.0.0 | 5.9.0 | 12.0+ |
v4.1.8 | 2024-03-24 | 15.0.0 | 5.9.0 | 12.0+ |
v4.1.7 | 2024-03-09 | 15.0.0 | 5.9.0 | 12.0+ |
v4.1.6 | 2024-02-16 | 15.0.0 | 5.9.0 | 12.0+ |
v4.1.5 | 2024-01-10 | 15.0.0 | 5.9.0 | 12.0+ |
v4.1.4 | 2023-12-24 | 15.0.0 | 5.9.0 | 12.0+ |
v4.1.3 | 2023-12-16 | 15.0.0 | 5.9.0 | 12.0+ |
v4.1.2 | 2023-12-02 | 15.0.0 | 5.9.0 | 12.0+ |
v4.1.1 | 2023-11-14 | 15.0.0 | 5.9.0 | 12.0+ |
v4.1.0 | 2023-11-07 | 15.0.0 | 5.9.0 | 12.0+ |
v4.0.9 | 2023-10-22 | 15.0.0 | 5.9.0 | 12.0+ |
v4.0.8 | 2023-10-13 | 15.0.0 | 5.9.0 | 12.0+ |
v4.0.7 | 2023-09-23 | 14.3.0 | 5.7.0 | 12.0+ |
v4.0.6 | 2023-09-09 | 14.3.0 | 5.7.0 | 12.0+ |
v4.0.5 | 2023-08-12 | 14.3.0 | 5.7.0 | 12.0+ |
v4.0.4 | 2023-07-30 | 14.3.0 | 5.7.0 | 12.0+ |
v4.0.3 | 2023-07-06 | 14.3.0 | 5.7.0 | 12.0+ |
v4.0.2 | 2023-06-24 | 14.3.0 | 5.7.0 | 12.0+ |
v4.0.1 | 2023-06-17 | 14.3.0 | 5.7.0 | 12.0+ |
v4.0.0 | 2023-06-15 | 14.3.0 | 5.7.0 | 12.0+ |
Choose a photo | Picture editing | Video editing |
---|---|---|
HXPhotoPicker is released under the MIT license. See LICENSE for details.
- ★ Star this repo.
- Support with