-
Notifications
You must be signed in to change notification settings - Fork 983
How to use (Swift)
long edited this page Sep 29, 2022
·
28 revisions
This class is a configuration class for framework, you can configure each parameter according to your needs.
// example
ZLPhotoConfiguration.default().allowSelectVideo = false
This class is a color configuration class for framework, you can configure each parameter according to your needs.
// example
ZLPhotoUIConfiguration.default().thumbnailBgColor = .black
let ps = ZLPhotoPreviewSheet()
ps.selectImageBlock = { [weak self] results, assets, isOriginal in
// your code
}
ps.showPreview(animate: true, sender: self)
let ps = ZLPhotoPreviewSheet()
ps.selectImageBlock = { [weak self] results, isOriginal in
// your code
}
ps.showPhotoLibrary(sender: self)
let cameraConfig = ZLPhotoConfiguration.default().cameraConfiguration
// All properties of the camera configuration have default value
cameraConfig.sessionPreset = .hd1920x1080
cameraConfig.focusMode = .continuousAutoFocus
cameraConfig.exposureMode = .continuousAutoExposure
cameraConfig.flashMode = .off
cameraConfig.videoExportType = .mov
let camera = ZLCustomCamera()
camera.takeDoneBlock = { [weak self] image, videoUrl in
// your code
}
self.showDetailViewController(camera, sender: nil)
// configuration UI
ZLPhotoUIConfiguration.default()
.navBarColor(.white)
// configuration of image editor
let editImageConfiguration = ZLPhotoConfiguration.default().editImageConfiguration
editImageConfiguration
.tools([.draw, .clip, .imageSticker, .textSticker, .mosaic, .filter, .adjust])
.clipRatios([.custom, .circle, .wh1x1, .wh3x4, .wh16x9, ZLImageClipRatio(title: "1 : 2", whRatio: 1 / 2)])
ZLPhotoConfiguration.default()
.editImageConfiguration(editImageConfiguration)
let editVC = ZLEditImageViewController(image: image)
editVC.editFinishBlock = { [weak self] image in
// your code
}
editVC.modalPresentationStyle = .fullScreen
self.showDetailViewController(editVC, sender: nil)
- About image sticker
You must provide a view that implements ZLImageStickerContainerDelegate. See this Demo.
@objc public var imageStickerContainerView: (UIView & ZLImageStickerContainerDelegate)? = nil
class CustomFilter {
class func filterMethod(image: UIImage) -> UIImage {
// 1. create filter.
// 2. process the image.
// 3. return the processed picture.
}
}
ZLPhotoConfiguration.default().filters = [ZLFilter(name: "custom", applier: CustomFilter.filterMethod)]
// edit local file.
let fileUrl = URL(fileURLWithPath: "filePath")
let avAsset = AVAsset(url: fileUrl)
let editVC = ZLEditVideoViewController(avAsset: avAsset, animateDismiss: true)
editVC.editFinishBlock = { url in
// your code
}
editVC.modalPresentationStyle = .fullScreen
self.showDetailViewController(editVC, sender: nil)
// Need to be consistent with the framework image name.
ZLPhotoConfiguration.default().customImageNames = ["zl_btn_selected"]
// or
ZLPhotoConfiguration.default().customImageForKey = ["zl_btn_selected": UIImage(named: "")]
ZLPhotoConfiguration.default().customLanguageKeyValue = [.previewCamera: "Camera"]
if #available(iOS 13.0, *) {
ZLPhotoConfiguration.default().themeColorDeploy.thumbnailBgColor = UIColor.init(dynamicProvider: { trait -> UIColor in
if trait.userInterfaceStyle == .dark {
return .black
} else {
return .white
}
})
}
// Must be one of PHAsset, UIImage and URL, framework will filter others.
let datas: [Any] = [...]
let videoSuffixs = ["mp4", "mov", "avi", "rmvb", "rm", "flv", "3gp", "wmv", "vob", "dat", "m4v", "f4v", "mkv"] // and more suffixs
let vc = ZLImagePreviewController(datas: datas, index: 0, showSelectBtn: true) { url -> ZLURLType in
if let sf = url.absoluteString.split(separator: ".").last, videoSuffixs.contains(String(sf)) {
return .video
} else {
return .image
}
} urlImageLoader: { url, imageView, progress, loadFinish in
// Demo used Kingfisher.
imageView.kf.setImage(with: url) { (receivedSize, totalSize) in
let percentage = (CGFloat(receivedSize) / CGFloat(totalSize))
progress(percentage)
} completionHandler: { (_) in
loadFinish()
}
}
vc.doneBlock = { datas in
// your code
}
vc.modalPresentationStyle = .fullScreen
self.showDetailViewController(vc, sender: nil)