Skip to content

ZhongUncle/SwiftUI_ImageCropper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SwiftUI_ImageCropper

Introduction

This is a simple cropper of images using SwiftUI. So you can customize the cropper easily and crop image in iOS/iPadOS even in macOS.

I make a demo in iOS/iPadOS to help you know how it works, and it also shows the size of image in pixel. It will show an image I inputted in advance. Then you can crop it in your mind, and touch the symbol "crop". The cropped image will show! It works like below in iPhone and iPad:

iPhone:

iPhone.mp4

iPad:

iPad.mov

You can follow the Usage to take SwiftUI_ImageCropper into your app or project! Enjoy it!

Usage

Step 1

Copy or drag "CropperView" and "CropImage" to your project. (The package is developping, coming soon)

Files' name

Step 2

Then you can use following code to call it in any View:

CropperView(inputImage: UIImage, croppedImage: Binding<UIImage>, cropBorderColor: Color?, cropVerticesColor: Color, cropperOutsideOpacity: Double)

There are some parameters for you to customize or use the cropper(If you want more, please "issue" me):

Parameter Type Default Description
inputImage UIImage You must assign it Image you want to be cropped
croppedImage Binding You must assign it The cropped image(it need you create a UIImage first), you can show or save it
cropBorderColor Color? Color.white As name said, it control the color of border of cropper
cropVerticesColor Color Color.pink As name said, it control the color of Vertices of cropper
cropperOutsideOpacity Double 0.4 The opacity of dark mask out of cropper

There are some demoes to show the changes in order (Defult vs Changed).

cropBorderColor: Defult vs Color.yellow cropBorderColor

cropVerticesColor: Defult vs Color.yellow cropVerticesColor

cropperOutsideOpacity: Defult vs 0.8 cropperOutsideOpacity

Notices

If you check the source code, you will find some issues "Invalid frame dimension (negative or non-finite)." Rest assured, they will not affect the operation.

Bugs

If you find a bug, please report it!

About

A cropper of images using SwiftUI.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages