Skip to content
long edited this page Mar 27, 2023 · 26 revisions

How to import header

  • Manually

    The system will automatically generate a class of target-Swfit.h (target is your project name), add #import "target-Swift.h" where you need to use it.

  • Others

    1. Need add use_frameworks! in Podfile.

    2. @import ZLPhotoBrowser; or #import <ZLPhotoBrowser/ZLPhotoBrowser-Swift.h>.

Because the singleton method name default in ZLPhotoConfiguration conflicts with the oc keyword, it cannot be called using dot syntax, and must be called with [ZLPhotoConfiguration default].

ZLPhotoConfiguration

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

// example
[ZLPhotoConfiguration default].allowSelectVideo = NO;

ZLPhotoUIConfiguration

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

// example
[ZLPhotoUIConfiguration default].themeColor = UIColor.blackColor;

Preview selection

ZLPhotoPreviewSheet *ps = [[ZLPhotoPreviewSheet alloc] initWithSelectedAssets:@[]];
//or
ZLPhotoPreviewSheet *ps = [[ZLPhotoPreviewSheet alloc] initWithResults:@[]];

ps.selectImageBlock = ^(NSArray<ZLResultModel *> * _Nonnull results, BOOL isOriginal) {
    // your code
};
[ps showPreviewWithAnimate:YES sender:self];

Library selection

ZLPhotoPreviewSheet *ps = [[ZLPhotoPreviewSheet alloc] initWithSelectedAssets:@[]];
ps.selectImageBlock = ^(NSArray<ZLResultModel *> * _Nonnull results, BOOL isOriginal) {
    // your code
};
[ps showPhotoLibraryWithSender:self];

Use custom camera

ZLCameraConfiguration *cameraConfig = [ZLPhotoConfiguration default].cameraConfiguration;
// All properties of the camera configuration have default value
cameraConfig.sessionPreset = CaptureSessionPresetHd1920x1080;
cameraConfig.focusMode = FocusModeContinuousAutoFocus;
cameraConfig.exposureMode = ExposureModeContinuousAutoExposure;
cameraConfig.flashMode = FlashModeOff;
cameraConfig.videoExportType = VideoExportTypeMov;

ZLCustomCamera *camera = [[ZLCustomCamera alloc] init];
camera.takeDoneBlock = ^(UIImage * _Nullable image, NSURL * _Nullable videoUrl) {
    
};
[self showDetailViewController:camera sender:nil];

Use image editor

Because Objective-C array can't contain Enum styles, so this property is invalid in Objective-C.

[ZLPhotoConfiguration default].editImageConfiguration.editImageClipRatios = @[ZLImageClipRatio.custom, ZLImageClipRatio.circle, ZLImageClipRatio.wh1x1, ZLImageClipRatio.wh3x4, ZLImageClipRatio.wh16x9, [[ZLImageClipRatio alloc] initWithTitle:@"1 : 2" whRatio:1.0 / 2.0]];

ZLEditImageViewController *editVC = [[ZLEditImageViewController alloc] initWithImage:image editModel:nil];
editVC.editFinishBlock = ^(UIImage * _Nonnull image, ZLEditImageModel * _Nonnull editModel) {
    // your code
};
editVC.modalPresentationStyle = UIModalPresentationFullScreen;
[vc 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

@interface CustomFilter : NSObject

+ (UIImage *)filterMethod:(UIImage *)image;

@end

@implementation CustomFilter

+ (UIImage *)filterMethod:(UIImage *)image
{
    // 1. create filter.
    // 2. process the image.
    // 3. return the processed picture.
}

@end

ZLFilter *filter = [[ZLFilter alloc] initWithName:@"custom" applier:^UIImage * _Nonnull(UIImage * _Nonnull image) {
    return [CustomFilter filterMethod:image];
}];
[ZLPhotoConfiguration default].editImageConfiguration.filters = @[filter];

Use video editor

// edit local file.
NSURL *fileUrl = [NSURL fileURLWithPath:@"filePath"];
AVAsset *avAsset = [AVAsset assetWithURL:fileUrl];
ZLEditVideoViewController *editVC = [[ZLEditVideoViewController alloc] initWithAvAsset:avAsset animateDismiss:YES];
editVC.editFinishBlock = ^(NSURL * _Nonnull url) {
    // your code
};
editVC.modalPresentationStyle = UIModalPresentationFullScreen;
[vc showDetailViewController:editVC sender:nil];

Customize image resource

// Need to be consistent with the framework image name.
[ZLPhotoUIConfiguration default].customImageNames = @[@"zl_btn_selected"];

Customize language

[ZLPhotoUIConfiguration default].customLanguageKeyValue_objc = @[@"previewCamera": @"Camera"];

Support light/dark mode

if (@available(iOS 13.0, *)) {
    UIColor *thumbnailBgColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
        if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
            return UIColor.blackColor;
        } else {
            return UIColor.whiteColor;
        }
    }];
    [ZLPhotoConfiguration default].themeColorDeploy.thumbnailBgColor = thumbnailBgColor;
}

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

// Must be one of PHAsset, UIImage and URL, framework will filter others.
NSArray *datas = @[...];
NSArray *videoSuffixs = @[@"mp4", @"mov", @"avi", @"rmvb", @"rm", @"flv", @"3gp", @"wmv", @"vob", @"dat", @"m4v", @"f4v", @"mkv"];

ZLImagePreviewController *vc = [[ZLImagePreviewController alloc] initWithDatas:datas index:0 showSelectBtn:YES urlType:^enum ZLURLType(NSURL * _Nonnull url) {
    NSString *format = [url.absoluteString componentsSeparatedByString:@"."].lastObject;
    if ([videoSuffixs containsObject:format]) {
        return ZLURLTypeVideo;
    } else {
        return ZLURLTypeImage;
    }
} urlImageLoader:^(NSURL * _Nonnull url, UIImageView * _Nonnull imageView, void (^ _Nonnull progress)(CGFloat), void (^ _Nonnull loadFinish)(void)) {
    [imageView sd_setImageWithURL:url placeholderImage:nil options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
        CGFloat percentage = (CGFloat)receivedSize / (CGFloat)expectedSize;
        progress(percentage);
    } completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        loadFinish();
    }];
}];

vc.doneBlock = ^(NSArray * _Nonnull datas) {
    // your code
};

vc.modalPresentationStyle = UIModalPresentationFullScreen;
[self showDetailViewController:vc sender:nil];