-
Notifications
You must be signed in to change notification settings - Fork 978
How to use (Swift)
long edited this page Aug 25, 2023
·
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 used to configure the framework UI style, including colors, languages, images, etc.
// example
ZLPhotoUIConfiguration.default()
.themeColor(.black)
.indexLabelBgColor(.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)
ZLPhotoConfiguration.default()
.cameraConfiguration
.allowRecordVideo(false)
.allowSwitchCamera(false)
.showFlashSwitch(true)
let camera = ZLCustomCamera()
camera.takeDoneBlock = { [weak self] image, videoUrl in
// your code
}
self.showDetailViewController(camera, sender: nil)
// configuration of image editor
ZLPhotoConfiguration.default()
.editImageConfiguration
.tools([.draw, .clip, .imageSticker, .textSticker, .mosaic, .filter, .adjust])
.clipRatios([.custom, .circle, .wh1x1, .wh3x4, .wh16x9, ZLImageClipRatio(title: "1 : 2", whRatio: 1 / 2)])
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()
.editImageConfiguration
.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.
ZLPhotoUIConfiguration.default()
.customImageNames(["zl_btn_selected"])
// or
ZLPhotoUIConfiguration.default()
.customImageForKey(["zl_btn_selected": UIImage(named: "")])
ZLPhotoUIConfiguration.default()
.customLanguageKeyValue([.previewCamera: "Camera"])
if #available(iOS 13.0, *) {
ZLPhotoUIConfiguration.default().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 percent = (CGFloat(receivedSize) / CGFloat(totalSize))
progress(percent)
} completionHandler: { _ in
loadFinish()
}
}
vc.doneBlock = { datas in
// your code
}
vc.modalPresentationStyle = .fullScreen
self.showDetailViewController(vc, sender: nil)