Skip to content
long edited this page Oct 10, 2020 · 28 revisions

在需要使用的地方添加 import ZLPhotoBrowser

ZLPhotoConfiguration

该类为框架配置类,可根据自己需要对各个参数进行配置

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

ZLPhotoThemeColorDeploy

该类为框架各个控件颜色配置类,可根据自己需要进行自定义

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

快速选择

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

直接进入相册选择

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

调用自定义相机

let camera = ZLCustomCamera()
camera.takeDoneBlock = { [weak self] (image, videoUrl) in
    // your code
}
self.showDetailViewController(camera, sender: nil)

调用编辑图片

// 设置编辑工具
ZLPhotoConfiguration.default().editImageTools = [.draw, .clip, .mosaic]
// 设置裁剪比例
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)

自定义滤镜

class CustomFilter {

    class func filterMethod(image: UIImage) -> UIImage {
        // 1.创建滤镜
        // 2.对image进行处理
        // 3.返回处理后的图片
    }

}

ZLPhotoConfiguration.default().filters = [ZLFilter(name: "custom", applier: CustomFilter.filterMethod)]

调用编辑视频

// 编辑本地视频
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)

自定义图片资源

// 与图片名字保持一致即可
ZLPhotoConfiguration.default().customImageNames = ["zl_btn_selected"]

自定义文案

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

支持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
        }
    })
}