- December 25, 2024
- Mins Read
Easily take a photo or video or choose from library
To run the example project, clone the repo, and run pod install
from the Example directory first.
To use it in your project, add an FDTakeController
to your view controller and implement:
fdTakeController.didGetPhoto = {
(_ photo: UIImage, _ info: [AnyHashable : Any]) in
}
then call:
fdTakeController.present()
The full API is:
/// Public initializer
public override init()
/// Convenience method for getting a photo
open class func getPhotoWithCallback(getPhotoWithCallback callback: @escaping (_ photo: UIImage, _ info: [AnyHashable : Any]) -> Void) -> <<error type>>
/// Convenience method for getting a video
open class func getVideoWithCallback(getVideoWithCallback callback: @escaping (_ video: URL, _ info: [AnyHashable : Any]) -> Void)
/// Whether to allow selecting a photo
open var allowsPhoto: Bool
/// Whether to allow selecting a video
open var allowsVideo: Bool
/// Whether to allow capturing a photo/video with the camera
open var allowsTake: Bool
/// Whether to allow selecting existing media
open var allowsSelectFromLibrary: Bool
/// Whether to allow editing the media after capturing/selection
open var allowsEditing: Bool
/// Whether to use full screen camera preview on the iPad
open var iPadUsesFullScreenCamera: Bool
/// Enable selfie mode by default
open var defaultsToFrontCamera: Bool
/// The UIBarButtonItem to present from (may be replaced by overloaded methods)
open var presentingBarButtonItem: UIBarButtonItem?
/// The UIView to present from (may be replaced by overloaded methods)
open var presentingView: UIView?
/// The UIRect to present from (may be replaced by overloaded methods)
open var presentingRect: CGRect?
/// The UITabBar to present from (may be replaced by overloaded methods)
open var presentingTabBar: UITabBar?
/// The UIViewController to present from (may be replaced by overloaded methods)
open lazy var presentingViewController: UIViewController { get set }
/// A photo was selected
open var didGetPhoto: ((_ photo: UIImage, _ info: [AnyHashable : Any]) -> Void)?
/// A video was selected
open var didGetVideo: ((_ video: URL, _ info: [AnyHashable : Any]) -> Void)?
/// The user did not attempt to select a photo
open var didDeny: (() -> Void)?
/// The user started selecting a photo or took a photo and then hit cancel
open var didCancel: (() -> Void)?
/// A photo or video was selected but the ImagePicker had NIL for EditedImage and OriginalImage
open var didFail: (() -> Void)?
/// Custom UI text (skips localization)
open var cancelText: String?
/// Custom UI text (skips localization)
open var chooseFromLibraryText: String?
/// Custom UI text (skips localization)
open var chooseFromPhotoRollText: String?
/// Custom UI text (skips localization)
open var noSourcesText: String?
/// Custom UI text (skips localization)
open var takePhotoText: String?
/// Custom UI text (skips localization)
open var takeVideoText: String?
/// Presents the user with an option to take a photo or choose a photo from the library
open func present()
/// Dismisses the displayed view. Especially handy if the sheet is displayed while suspending the app,
open func dismiss()
Other available options are documented at CocoaDocs for FDTake.
FDTake.strings
to more languagesAdd this to your project using Swift Package Manager. In Xcode that is simply: File > Swift Packages > Add Package Dependency… and you’re done. Alternative installation options are shown below for legacy projects.
If you are already using CocoaPods, just add ‘FDTake’ to your Podfile
then run pod install
.
If you are already using Carthage, just add to your Cartfile
:
github “fulldecent/FDTake”
Then run carthage update
to build the framework and drag the built FDTake
.framework into your Xcode project.