- Notifications
You must be signed in to change notification settings - Fork1k
How to use (Swift)
long edited this pageJul 23, 2025 ·29 revisions
This class is a configuration class for framework, you can configure each parameter according to your needs.
// exampleZLPhotoConfiguration.default().allowSelectVideo=false
This class is used to configure the framework UI style, including colors, languages, images, etc.
// exampleZLPhotoUIConfiguration.default().themeColor(.black).indexLabelBgColor(.black)
letpicker=ZLPhotoPicker()picker.selectImageBlock={[weak self] results, assets, isOriginalin // your code}picker.showPreview(animate:true, sender:self)
letpicker=ZLPhotoPicker()picker.selectImageBlock={[weak self] results, isOriginalin // your code}picker.showPhotoLibrary(sender:self)
ZLPhotoConfiguration.default().cameraConfiguration.allowRecordVideo(false).allowSwitchCamera(false).showFlashSwitch(true)letcamera=ZLCustomCamera()camera.takeDoneBlock={[weak self] image, videoUrlin // your code}self.showDetailViewController(camera, sender:nil)
// configuration of image editorZLPhotoConfiguration.default().editImageConfiguration.tools([.draw,.clip,.imageSticker,.textSticker,.mosaic,.filter,.adjust]).clipRatios([.custom,.circle,.wh1x1,.wh3x4,.wh16x9,ZLImageClipRatio(title:"1 : 2", whRatio:1/2)])leteditVC=ZLEditImageViewController(image: image)editVC.editFinishBlock={[weak self] imagein // your code}editVC.modalPresentationStyle=.fullScreenself.showDetailViewController(editVC, sender:nil)
- About image sticker
You must provide a view that implements ZLImageStickerContainerDelegate.See thisDemo.
@objc public var imageStickerContainerView: (UIView & ZLImageStickerContainerDelegate)? = nilclassCustomFilter{classfunc 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.letfileUrl=URL(fileURLWithPath:"filePath")letavAsset=AVAsset(url: fileUrl)leteditVC=ZLEditVideoViewController(avAsset: avAsset, animateDismiss:true)editVC.editFinishBlock={ urlin // your code}editVC.modalPresentationStyle=.fullScreenself.showDetailViewController(editVC, sender:nil)
// Need to be consistent with the framework image name.ZLPhotoUIConfiguration.default().customImageNames(["zl_btn_selected"])// orZLPhotoUIConfiguration.default().customImageForKey(["zl_btn_selected":UIImage(named:"")])
ZLPhotoUIConfiguration.default().customLanguageKeyValue([.previewCamera:"Camera"])
if #available(iOS13.0,*){ZLPhotoUIConfiguration.default().thumbnailBgColor=UIColor.init(dynamicProvider:{ trait->UIColorinif trait.userInterfaceStyle==.dark{return.black}else{return.white}})}
// Must be one of PHAsset, UIImage and URL, framework will filter others.letdatas:[Any]=[...]letvideoSuffixs=["mp4","mov","avi","rmvb","rm","flv","3gp","wmv","vob","dat","m4v","f4v","mkv"] // and more suffixsletvc=ZLImagePreviewController(datas: datas, index:0, showSelectBtn:true){ url->ZLURLTypeiniflet sf= url.absoluteString.split(separator:".").last, videoSuffixs.contains(String(sf)){return.video}else{return.image}} urlImageLoader:{ url, imageView, progress, loadFinishin // Demo used Kingfisher. imageView.kf.setImage(with: url){ receivedSize, totalSizeinletpercent=(CGFloat(receivedSize)/ CGFloat(totalSize))progress(percent)} completionHandler:{ _inloadFinish()}}vc.doneBlock={ datasin // your code}vc.modalPresentationStyle=.fullScreenself.showDetailViewController(vc, sender:nil)