Skip to content
long edited this page Aug 25, 2023 · 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

ZLPhotoUIConfiguration

This class is used to configure the framework UI style, including colors, languages, images, etc.

// example
ZLPhotoUIConfiguration.default()
    .themeColor(.black)
    .indexLabelBgColor(.black)

Preview selection

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

Library selection

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

Use custom camera

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)

Use image editor

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

Customize filter

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

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.
ZLPhotoUIConfiguration.default()
    .customImageNames(["zl_btn_selected"])
// or
ZLPhotoUIConfiguration.default()
    .customImageForKey(["zl_btn_selected": UIImage(named: "")])

Customize language

ZLPhotoUIConfiguration.default()
    .customLanguageKeyValue([.previewCamera: "Camera"])

Support light/dark mode

if #available(iOS 13.0, *) {
    ZLPhotoUIConfiguration.default().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 percent = (CGFloat(receivedSize) / CGFloat(totalSize))
        progress(percent)
    } completionHandler: { _ in
        loadFinish()
    }
}

vc.doneBlock = { datas in
    // your code
}

vc.modalPresentationStyle = .fullScreen
self.showDetailViewController(vc, sender: nil)