FYPhoto is an photo/video picker and browser for iOS written in pure Swift. It is feature-rich and highly customizable to match your App's requirements.
To run the example project, clone the repo, and run pod install
from the Example directory first.
Installation - Configuration - Usage - Languages - UI Customization
Give it a quick try :
pod repo update
then pod try FYPhoto
Those features are available just with a few lines of code!
π· Photo
π₯ Video
βοΈ Crop
β‘οΈ Flash
π§ Watermark
π Albums
π’ Multiple Selection
π Video Trimming
And many more...
iOS 11 or later
Using CocoaPods
First be sure to run pod repo update
to get the latest version available.
Add pod 'FYPhoto'
to your Podfile
and run pod install
. Also add use_frameworks!
to the Podfile
.
target 'MyApp'
pod 'FYPhoto'
use_frameworks!
Using Swift Package Manager
Swift Package Manager (SwiftPM) is a tool for managing the distribution of Swift code as well as C-family dependency. From Xcode 11, SwiftPM got natively integrated with Xcode.
FYPhoto support SwiftPM from version 2.1.0. To use SwiftPM, you should use Xcode 11 to open your project. Click File
-> Swift Packages
-> Add Package Dependency
, enter FYPhoto repo's URL. Or you can login Xcode with your GitHub account and just type FYPhoto
to search.
After select the package, you can choose the dependency type (tagged version, branch or commit). Then Xcode will setup all the stuff for you.
If you're a framework author and use FYPhoto as a dependency, update your Package.swift file:
let package = Package(
dependencies: [
.package(url: "https://github.com/T2Je/FYPhoto.git", from: "2.2.9")
],
// ...
)
In order for your app to access camera and photo libraries,
you'll need to ad these plist entries
:
- Privacy - Camera Usage Description (photo/videos)
- Privacy - Photo Library Usage Description (library)
- Privacy - Microphone Usage Description (videos)
<key>NSCameraUsageDescription</key>
<string>yourWording</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>yourWording</string>
<key>NSMicrophoneUsageDescription</key>
<string>yourWording</string>
All the configuration endpoints are in the FYPhotoPickerConfiguration. Below are the default value for reference, feel free to play around :)
var pickerConfig = FYPhotoPickerConfiguration()
// [Edit configuration here ...]
// Build a picker with your configuration
let photoPicker = PhotoPickerViewController(configuration: pickerConfig)
pickerConfig.selectionLimit = 0
pickerConfig.supportCamera = true
pickerConfig.mediaFilter = [.image, .video]
// Color
let colorConfig = FYColorConfiguration()
colorConfig.topBarColor = FYColorConfiguration.BarColor(itemTintColor: .red,
itemDisableColor: .gray,
itemBackgroundColor: .black,
backgroundColor: .blue)
// Similar setting code for pickerBottomBarColor and browserBottomBarColor
pickerConfig.colorConfiguration = colorConfig
pickerConfig.compressedQuality = .mediumQuality
pickerConfig.maximumVideoMemorySize = 40 // MB
pickerConfig.maximumVideoDuration = 15 // Secs
let photoBrowser = PhotoBrowserViewController.create(photos: photos, initialIndex: 0)
let photosBrowser = PhotoBrowserViewController.create(photos: [photo],
initialIndex: 0) {
$0
.buildPageControl()
.buildBottomToolBar()
.buildNavigationBar()
.buildCaption()
.buildThumbnailsForSelection()
.showDeleteButtonForBrowser()
.setMaximumCanBeSelected(1)
}
First things first import FYPhoto
.
let photoPickerVC = PhotoPickerViewController(configuration: pickerConfig)
photoPickerVC.selectedPhotos = { [weak self] images in
// images.forEach {
// $0.asset
// $0.data
// $0.image
// }
}
photoPickerVC.selectedVideo = { [weak self] selectedResult in
switch selectedResult {
case .success(let video):
// video.briefImage
// video.url
case .failure(let error):
print("selected video error: \(error)")
}
}
photoPickerVC.modalPresentationStyle = .fullScreen
self.present(photoPickerVC, animated: true, completion: nil)
let image = Photo.photoWithURL(url) // Similar init method for asset, image, data
let photoBrowser = PhotoBrowserViewController.create(photos: [image], initialIndex: 0)
// Use `.fyphoto` to easily bring smoothly drag-drop animation to your app.
self.fyphoto.present(photoBrowser, animated: true, completion: nil)
That's it !
πΊπΈ English, π¨π³ Chinese.
If your language is not supported, you can submit an issue or pull request with your Localizable.strings
file to add a new language !
We tried to keep things as native as possible, so this is done mostly through native Apis.
This project references the following projects:
FYPhoto relies on SDWebImage to provide async image downloader with cache support.
Objective-C is not supported and this is not on our roadmap. Swift is the future and dropping Obj-C is the price to pay to keep our velocity on this library :)
Add more features to edit photo, include Filter
, Mosaic
, etc.
FYPhoto is released under the MIT license.
Swift 5.4.