Giter Site home page Giter Site logo

mohsinalimat / lecroppictureviewcontroller Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lucasecf/lecroppictureviewcontroller

1.0 2.0 1.0 1.83 MB

A nice controller to crop round or rect images

License: MIT License

Objective-C 68.46% Ruby 3.32% C 2.74% Shell 25.48%

lecroppictureviewcontroller's Introduction

LECropPictureViewController

What is this

Want a nice crop editor for your picture? Not satisfied with the one provided for Apple? Likes rounded images? LECropPictureViewController is the component for you :)! See the how works in the gif below:

GIF 1

Install

Manually

Drag and copy all files in the LECropPictureViewController folder into your project, or add it as a git submodule.

Cocoapods

LECropPictureViewController is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "LECropPictureViewController", "~> 0.1"

How to use

LECropPictureViewController works with any image. You just have to provide the image and a cropType when creating a new instance, and then present the view controller. The possible cropTypes are:

  • LECropPictureTypeRounded
  • LECropPictureTypeRect
#import "LECropPictureViewController.h"

LECropPictureViewController *cropPictureController = [[LECropPictureViewController alloc] initWithImage:image andCropPictureType:LECropPictureTypeRounded];
[self presentViewController:cropPictureController animated:YES completion:nil];

The callback for the cropped picture is given through a block. See the exemple below, presenting the LECropPictureViewController inside the delegate of a UIImagePickerController:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
    UIImage *image = info[UIImagePickerControllerOriginalImage];

    [self dismissViewControllerAnimated:NO completion:nil];

    LECropPictureViewController *cropPictureController = [[LECropPictureViewController alloc] initWithImage:image andCropPictureType:LECropPictureTypeRounded];
    cropPictureController.imageView.contentMode = UIViewContentModeScaleAspectFit;

    cropPictureController.photoAcceptedBlock = ^(UIImage *croppedPicture){
        self.imageView.image = croppedPicture;
    };

    [self presentViewController:cropPictureController animated:NO completion:nil];
}

Customizing

The LECropPictureViewController has public properties for it's components. With this, you can do things like changing the contentMode of the imageView, changing the text of the barButtonItems, etc.

@property (weak, nonatomic) UIBarButtonItem *cancelButtonItem;
@property (weak, nonatomic) UIBarButtonItem *acceptButtonItem;
@property (weak, nonatomic) UIImageView *imageView;

Besides the subviews, you can customize other things like the initial frame of the crop area, borderColor and borderWidth, like below:

(...)
LECropPictureViewController *cropPictureController = [[LECropPictureViewController alloc] initWithImage:image andCropPictureType:LECropPictureTypeRounded];
cropPictureController.cropFrame = CGRectMake(50, 50, 250, 250);
cropPictureController.borderColor = [UIColor grayColor];
cropPictureController.borderWidth = 1.0;
(...)

You can even implement the @property(copy) void(^photoRejectedBlock)();, if you want to override the default behaviour of the cancel button (which only dismiss the controller). Be aware that, if you do this, you will be responsible to dismiss the controller yourself.

cropPictureController.photoRejectedBlock = ^{
    NSLog(@"Doing something here!");
    [self dismissViewControllerAnimated:YES completion:nil];
};

Collaborate

Liked the project? Is there something missing or that could be better? Feel free to contribute :)

  1. Fork it

  2. Create your branch git checkout -b name-your-feature

  3. Commit it git commit -m 'the difference'

  4. Push it git push origin name-your-feature

  5. Create a Pull Request

Author

Lucas Eduardo, [email protected]

License

LECropPictureViewController is available under the MIT license. See the LICENSE file for more info.

lecroppictureviewcontroller's People

Contributors

lucasecf avatar ntnmrndn avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

jsooriah

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.