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: 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 its 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 :) Fork it Create your branch git checkout -b name-your-feature Commit it git commit -m the difference Push it git push origin name-your-feature Create a Pull Request Author Lucas Eduardo, lucasecf@gmail.com License LECropPictureViewController is available under the MIT license. See the LICENSE file for more info.
A nice controller to crop round or rect images
3997
来源:
Licence:
联系:
分类:
平台:
环境:
大小:
更新:
标签:
免费下载
×
温馨提示
请用电脑打开本网页,即可以免费获取你想要的了。
