一个简单、可定制的方形缩放手和裁剪视图控制器
只需用 #import BASSquareCropperViewController.h
导入裁剪器即可。
监听以下代理方法:
- (void)squareCropperDidCropImage:(UIImage *)croppedImage inCropper:(BASSquareCropperViewController *)cropper
- (void)squareCropperDidCancelCropInCropper:(BASSquareCropperViewController *)cropper
并根据您的应用程序应该如何工作来处理它们。
使用图像和最小裁剪图像边长初始化裁剪器,如下所示(边长为 0.0f 表示无限制):BASSquareCropperViewController *squareCropperViewController = [[BASSquareCropperViewController alloc] initWithImage:imageToCrop minimumCroppedImageSideLength:400.0f];
别忘了设置委托! squareCropperViewController.squareCropperDelegate = self;
从这里开始,建议模态呈现此视图控制器,但不是必需的。
如果您想获取裁剪后的矩形与原始图像相比,只需在关闭之前的代理回调中访问 BASSquareCropperViewController
上的 cropRect
属性即可。
以下属性可设置以调整裁剪器的外观和感觉
@property (nonatomic, strong) UIColor *backgroundColor;
@property (nonatomic, strong) UIColor *borderColor;
@property (nonatomic, strong) UIColor *excludedBackgroundColor;
@property (nonatomic, strong) UIFont *doneFont;
@property (nonatomic, strong) UIColor *doneColor;
@property (nonatomic, copy) NSString *doneText;
@property (nonatomic, strong) UIFont *cancelFont;
@property (nonatomic, strong) UIColor *cancelColor;
@property (nonatomic, copy) NSString *cancelText;
只需初始化裁剪器,然后根据需要设置以下任一项,例如
squareCropperViewController.backgroundColor = [UIColor whiteColor];
squareCropperViewController.borderColor = [UIColor redColor];
squareCropperViewController.doneColor = [UIColor orangeColor];
squareCropperViewController.doneFont = [UIFont fontWithName:@"Avenir-Roman" size:30.0f];
squareCropperViewController.doneText = @"FINISHED";
squareCropperViewController.cancelColor = [UIColor greenColor];
squareCropperViewController.cancelFont = [UIFont fontWithName:@"Avenir-Black" size:25.0f];
squareCropperViewController.cancelText = @"STOP";
squareCropperViewController.excludedBackgroundColor = [UIColor blackColor];
这看起来像极差的垃圾,但你可以理解这个意思。任何未修改的东西都将默认为截图中所显示的内容。
BASSquareCropperController 受 MIT 许可证的保护。