FYPhoto
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.
Example
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!
Notable Features
And many more...
Requirements
iOS 11 or later
Installation
CocoaPods
UsingFirst 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!
Swift Package Manager
UsingSwift 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.
Plist entries
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>NSCameraUsageDescriptionkey>
<string>yourWordingstring>
<key>NSPhotoLibraryUsageDescriptionkey>
<string>yourWordingstring>
<key>NSMicrophoneUsageDescriptionkey>
<string>yourWordingstring>
Configuration
All the configuration endpoints are in the FYPhotoPickerConfiguration. Below are the default value for reference, feel free to play around :)
Picker
var pickerConfig = FYPhotoPickerConfiguration()
// [Edit configuration here ...]
// Build a picker with your configuration
let photoPicker = PhotoPickerViewController(configuration: pickerConfig)
General
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
Video
pickerConfig.compressedQuality = .mediumQuality
pickerConfig.maximumVideoMemorySize = 40 // MB
pickerConfig.maximumVideoDuration = 15 // Secs
Browser
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)
}
Usage
First things first import FYPhoto
.
Picker
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)
Browser
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 !
Languages
If your language is not supported, you can submit an issue or pull request with your Localizable.strings
file to add a new language !
UI Customization
We tried to keep things as native as possible, so this is done mostly through native Apis.
References
This project references the following projects:
Dependency
FYPhoto relies on SDWebImage to provide async image downloader with cache support.
Obj-C 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 :)
Plan
Add more features to edit photo, include Filter
, Mosaic
, etc.
License
FYPhoto is released under the MIT license.
Swift Version
Swift 5.4.