From efcb0c3b93a6723bea3fd68c302bcf176b4ea098 Mon Sep 17 00:00:00 2001 From: Guilherme Mogames Date: Thu, 29 Oct 2015 11:08:28 -0400 Subject: [PATCH 1/2] Adding init option to change the overlay backgroundColor --- Pod/Classes/LECropPictureViewController.h | 23 ++++++++++++++++- Pod/Classes/LECropPictureViewController.m | 30 ++++++++++++++--------- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/Pod/Classes/LECropPictureViewController.h b/Pod/Classes/LECropPictureViewController.h index 70df53a..472f124 100644 --- a/Pod/Classes/LECropPictureViewController.h +++ b/Pod/Classes/LECropPictureViewController.h @@ -42,6 +42,16 @@ typedef NS_ENUM(NSUInteger, LECropPictureType) { */ @property (nonatomic, readonly) LECropPictureType cropPictureType; +/** + Readonly property, to tell if the controller what is the overlay background color. + */ +@property (nonatomic, readonly) UIColor *backgroundColor; + + +/** + Controls the background color of the crop overlay. Default is black. + */ +@property(nonatomic) UIColor *overlayColor; /** Controls the border width for the crop component. Default value is 2.0. @@ -92,4 +102,15 @@ typedef NS_ENUM(NSUInteger, LECropPictureType) { */ - (instancetype)initWithImage:(UIImage*)image andCropPictureType:(LECropPictureType)cropPictureType; -@end +/** + Extra init for this component. + + @param image Image that will be cropped by the controller. + + @param backgroundColor sets the background color of the overlay that goes on top of the image. + + @param cropPictureType Tells if the crop component will crop the image as a circle or a square. Check the LECropPictureType enum to see the possible values. + + */ +- (instancetype)initWithImage:(UIImage*)image backgroundColor:(UIColor *)backgroundColor andCropPictureType:(LECropPictureType)cropPictureType; +@end \ No newline at end of file diff --git a/Pod/Classes/LECropPictureViewController.m b/Pod/Classes/LECropPictureViewController.m index d1321b7..07a543a 100644 --- a/Pod/Classes/LECropPictureViewController.m +++ b/Pod/Classes/LECropPictureViewController.m @@ -23,24 +23,30 @@ @implementation LECropPictureViewController static const CGFloat toolbarHeight = 44; -- (instancetype)initWithImage:(UIImage*)image andCropPictureType:(LECropPictureType)cropPictureType -{ +- (instancetype)initWithImage:(UIImage*)image backgroundColor:(UIColor *)backgroundColor andCropPictureType:(LECropPictureType)cropPictureType{ self = [super init]; if (self) { _image = image; _cropPictureType = cropPictureType; + _backgroundColor = backgroundColor; //default values _cropFrame = CGRectNull; _borderWidth = 2.0; _borderColor = [UIColor whiteColor]; + //load subviews [self loadComponents]; } return self; } +- (instancetype)initWithImage:(UIImage*)image andCropPictureType:(LECropPictureType)cropPictureType +{ + return [self initWithImage:image backgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.7] andCropPictureType:cropPictureType]; +} + - (CGRect)cropFrame { if (!CGRectIsNull(_cropFrame)) { return _cropFrame; @@ -53,30 +59,30 @@ - (CGRect)cropFrame { -(void)loadComponents { UIToolbar *toolBar = [[UIToolbar alloc] init]; self.toolBar = toolBar; - + UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain target:self action:@selector(didTouchCancelButton)]; - + UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Accept" style:UIBarButtonItemStylePlain target:self action:@selector(didTouchAcceptButton)]; - + [toolBar setItems:@[leftButton, flexibleSpace, rightButton]]; self.cancelButtonItem = leftButton; self.acceptButtonItem = rightButton; - + UIImageView *imageView = [[UIImageView alloc] initWithImage:self.image]; imageView.contentMode = UIViewContentModeScaleAspectFit; imageView.userInteractionEnabled = YES; - + self.imageView = imageView; - + for (UIView *view in @[imageView, toolBar]) { view.translatesAutoresizingMaskIntoConstraints = NO; } - + [self.view addSubview:imageView]; [self.view addSubview:toolBar]; - + NSDictionary *viewsDictionnary = NSDictionaryOfVariableBindings(toolBar, imageView); [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:[NSString stringWithFormat:@"V:|[imageView][toolBar(%f)]|", toolbarHeight] options:0 metrics:nil views:viewsDictionnary]]; [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[imageView]|" options:0 metrics:nil views:viewsDictionnary]]; @@ -87,10 +93,10 @@ -(void)loadComponents { - (void)viewDidLayoutSubviews { CGRect frame = self.imageView.frame; self.overlay = [[CameraCropOverlay alloc] initWithFrame:frame - backgroundColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.7] + backgroundColor:_backgroundColor cropPictureType:self.cropPictureType andOverlayFrame:self.cropFrame]; - + self.overlay.cropView.layer.borderColor = _borderColor.CGColor; self.overlay.cropView.layer.borderWidth = _borderWidth; self.overlay.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; From 744ccae3afe35b78c3645e51a3f799f36e6ac3c0 Mon Sep 17 00:00:00 2001 From: Guilherme Mogames Date: Fri, 30 Oct 2015 08:53:27 -0400 Subject: [PATCH 2/2] Removing unused property --- Pod/Classes/LECropPictureViewController.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Pod/Classes/LECropPictureViewController.h b/Pod/Classes/LECropPictureViewController.h index 472f124..232f19e 100644 --- a/Pod/Classes/LECropPictureViewController.h +++ b/Pod/Classes/LECropPictureViewController.h @@ -47,12 +47,6 @@ typedef NS_ENUM(NSUInteger, LECropPictureType) { */ @property (nonatomic, readonly) UIColor *backgroundColor; - -/** - Controls the background color of the crop overlay. Default is black. - */ -@property(nonatomic) UIColor *overlayColor; - /** Controls the border width for the crop component. Default value is 2.0. */