Skip to content
long edited this page Apr 26, 2021 · 28 revisions

ZLPhotoConfiguration

This class is a configuration class for framework, you can configure each parameter according to your needs.

// example
ZLPhotoConfiguration.default().allowSelectVideo = false

ZLPhotoThemeColorDeploy

This class is a color configuration class for framework, you can configure each parameter according to your needs.

// example
ZLPhotoConfiguration.default().themeColorDeploy.thumbnailBgColor = .black

Preview selection

let ps = ZLPhotoPreviewSheet()
ps.selectImageBlock = { [weak self] (images, assets, isOriginal) in
    // your code
}
ps.showPreview(animate: true, sender: self)

Library selection

let ps = ZLPhotoPreviewSheet()
ps.selectImageBlock = { [weak self] (images, assets, isOriginal) in
    // your code
}
ps.showPhotoLibrary(sender: self)

Use custom camera

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)

Use image editor

// config edit tools
ZLPhotoConfiguration.default().editImageTools = [.draw, .clip, .mosaic]
// config crop ratios
ZLPhotoConfiguration.default().editImageClipRatios = [.custom, .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

Customize filter

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)]

Use video editor

// 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)

Customize image resource

// Need to be consistent with the framework image name.
ZLPhotoConfiguration.default().customImageNames = ["zl_btn_selected"]

Customize language

ZLPhotoConfiguration.default().customLanguageKeyValue = [.previewCamera: "Camera"]

Support light/dark mode

if #available(iOS 13.0, *) {
    ZLPhotoConfiguration.default().themeColorDeploy.thumbnailBgColor = UIColor.init(dynamicProvider: { (trait) -> UIColor in
        if trait.userInterfaceStyle == .dark {
            return .black
        } else {
            return .white
        }
    })
}

Preview PHAsset, local image, local video, network image, network video together

// 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)