Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Pod/Classes/LECropPictureViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ 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 border width for the crop component. Default value is 2.0.
Expand Down Expand Up @@ -92,4 +96,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
30 changes: 18 additions & 12 deletions Pod/Classes/LECropPictureViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]];
Expand All @@ -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;
Expand Down