EasierPath is a library to make UIBezierPath easier to use

Overview

EasierPath ⚡️

CI Status Version License Platform Platform

EasierPath is a library to make UIBezierPath easier to use. More specifically, you can write more intuitive and concise code when you draw a straight line or a curve.

Why use EasierPath? 🤷

If you draw the shape of a jar using UIBezierPath, you will write the code as below.

image

1. Create a UIBezierPath instance and draw a line and connect it.

let bezierPath:UIBezierPath = UIBezierPath()
bezierPath.move(to: CGPoint(x: 100, y: 100))
bezierPath.addLine(to: CGPoint(x: 200, y: 100))
bezierPath.addCurve(to: CGPoint(x: 200, y: 300), controlPoint1: CGPoint(x: 250, y: 150), controlPoint2: CGPoint(x: 175, y: 250))
bezierPath.addLine(to: CGPoint(x:100,y:300))
bezierPath.addCurve(to: CGPoint(x: 100, y: 100), controlPoint1: CGPoint(x: 125, y: 250), controlPoint2: CGPoint(x: 50, y: 150))
bezierPath.close()

2. Apply the path of CAShapeLayer as UIBezierPath's cgPath and apply the desired style.

let caShapeLayer:CAShapeLayer = CAShapeLayer()
caShapeLayer.path = bezierPath.cgPath
caShapeLayer.strokeColor = UIColor.white.cgColor
caShapeLayer.fillColor = UIColor.systemPink.cgColor
caShapeLayer.lineWidth = 3

3. Add it to the subLayer of the view.

view.layer.addSublayer(caShapeLayer)

UIBezierPath had several disadvantages in writing the above code. 😮‍💨

1. Remember the end point when adding lines in your head. 😵‍💫

Before drawing a line or curve, I had to remember where it ended and set the point accordingly.

The more we drew this, the more we had to remember, and it was so unclear to check through the code.

2. If the starting point changes, all points must be modified. 😓

Each line or the curved point is drawn based on the starting point, so if the starting point changed, you had to change the points of all the lines.

If you didn't want to do that, you could have used a certain variable to put the value and then designated it, but this was also a hassle.

3. Create CAShapeLayer or UIView. 😩

In order to display UIBezierPath in View, there was a hassle of applying the path created by creating CAShapeLayer, or creating a UIView and drawing it directly into the draw() method.

Let's write a code using EasierPath to make the same shape of the jar below. 👊

image

1. Create and draw an instance of EasierPath.

let easierPath = EasierPath(100,100)
            .right(100)
            .curve(to: .down(200), .bezier(.rightDown(50,50), .leftDown(25,150)))
            .left(100)
            .curve(to:.up(200), .bezier(.rightUp(25,50), .leftUp(50,150)))

2. Make layers for the style you want.

let layer = easierPath.makeLayer(lineWidth:3,lineColor: .white,fillColor:.systemPink)

3. Add it to the subLayer of the view.

view.layer.addSublayer(layer)

EasierPath can compensate for all of these shortcomings. 😎

1. You don't have to remember the end point when adding a line. 😄

Using the above EasierPath, you don't have to remember where it ended before, just specify which direction to draw the line.

2. Even if the starting point changes, the code remains the same. 🤗

Even if the starting point changes, you do not need to change each point because it is drawn in a direction based on that point.

3. Create a layer using the makeLayer method. 🤩

You don't have to create a CAShapeLayer or UIView, but you can create a layer if you specify a style using the makeLayer method in EasierPath.

You can also make the shapes you want simple 😋

   let shape = EasierPath(Shape, CGRect())
square circle rectangle oval triangle rhombus
스크린샷 2022-06-12 오후 5 43 43 스크린샷 2022-06-12 오후 5 38 54 스크린샷 2022-06-12 오후 5 39 29 스크린샷 2022-06-12 오후 5 39 15 스크린샷 2022-06-12 오후 5 39 50 스크린샷 2022-06-12 오후 5 38 36

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • iOS 13.0+
  • Swift 5.0+

Installation

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

pod 'EasierPath'

Test Coverage

100%

Author

Fomagran, [email protected]

License

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

You might also like...
NavigationCoordinator acts as a coordinator for NavigationView in SwiftUI. You can use pushView, popView, popToView, popToRootView as you can in traditional UIKit

NavigationCoordinator NavigationCoordinator acts as a coordinator for NavigationView. You can use pushView, popView, popToView, popToRootView in Swift

Use Swift to pack ambiguous image that display differently on Apple and Other devices

Aibmoe Use Swift to pack ambiguous image that display differently on Apple and O

Small color quantizer for bitmaps without any dependencies or use of frameworks

MicroColorQuantizer This package currently offers a very simple color quantizer

An example app showing how to use AVCaptureSession with Metal in Swift.
An example app showing how to use AVCaptureSession with Metal in Swift.

#iOSSwiftMetalCamera Click here to see video demo. This app is a basic example showing how to use Swift to setup an AVCaptureSession session to access

Use `PreselectedPhotoViewController` to handle limited photo access case in your app.
Use `PreselectedPhotoViewController` to handle limited photo access case in your app.

PreselectedPhotoUI Use PreselectedPhotoViewController to handle limited photo access case in your app. Overview Supports iOS 14.0 or later How to use?

AlamofireImage is an image component library for Alamofire

AlamofireImage AlamofireImage is an image component library for Alamofire. Features Image Response Serializers UIImage Extensions for Inflation / Scal

CTPanoramaView is a library that displays spherical or cylindrical panoramas with touch or motion based controls.
CTPanoramaView is a library that displays spherical or cylindrical panoramas with touch or motion based controls.

CTPanoramaView is a high-performance library that uses SceneKit to display complete spherical or cylindrical panoramas with touch or motion based controls.

A Swift client library for generating URLs with imgix

imgix-swift is a client library for generating image URLs with imgix. Written in Swift, but can be used with Objective-C codebases as well. Installati

Kanvas is an open-source iOS library for adding effects, drawings, text, stickers, and making GIFs from existing media or the camera.
Kanvas is an open-source iOS library for adding effects, drawings, text, stickers, and making GIFs from existing media or the camera.

Kanvas Kanvas is an open-source iOS library for adding effects, drawings, text, stickers, and making GIFs from existing media or the camera.

Releases(1.1.1)
Owner
UISugar⚡️
Make the UI easier to use ⚡️
UISugar⚡️
SwiftGen is a tool to automatically generate Swift code for resources of your projects (like images, localised strings, etc), to make them type-safe to use.

SwiftGen is a tool to automatically generate Swift code for resources of your projects (like images, localised strings, etc), to make them type-safe to use.

null 8.3k Jan 5, 2023
XcodeColorSense - An Xcode plugin that makes working with color easier.

XcodeColorSense An Xcode plugin that makes working with color easier. Inspired by ColorSense-for-Xcode with extra care for Hex color Features Show col

Khoa 77 Jul 1, 2022
A view that takes a set of images, make transition from one to another by using flipping effects.

CDFlipView A view that takes a set of images, make transition from one to another by using flipping effects. Demo Live Demo: https://appetize.io/app/w

Jianbin LIN 99 Aug 27, 2021
Make system color defined in UIColor/NSColor available to SwiftUI Color.

SwiftUIColor Make system color defined in UIColor/NSColor available to SwiftUI Color. About In this library, colors are defined in an asset file. Crea

null 2 Oct 24, 2022
Lightbox is a convenient and easy to use image viewer for your iOS app

Lightbox is a convenient and easy to use image viewer for your iOS app, packed with all the features you expect: Paginated image slideshow. V

HyperRedink 1.5k Dec 22, 2022
A smart and easy-to-use image masking and cutout SDK for mobile apps.

TinyCrayon SDK for iOS A smart and easy-to-use image masking and cutout SDK for mobile apps. TinyCrayon SDK provides tools for adding image cutout and

null 1.8k Dec 30, 2022
You can use blur effect and it's animation easily to call only two methods.

SABlurImageView You can use blur effect and it's animation easily to call only two methods. ManiacDev.com referred. https://maniacdev.com/2015/04/open

Taiki Suzuki 555 Dec 17, 2022
Very easy to use image loader for swift

Silo Silo is a extremely easy to use and very basic image loader for iOS built in Swift. if you use Silo in your project please let me know! Version 2

Jose Quintero 17 Dec 17, 2022
Gallery has a clearer flow based on albums and focuses on the use case of selecting video

Description We all love image pickers, don't we? You may already know of ImagePicker, the all in one solution for capturing pictures and selecting ima

null 1 Sep 14, 2022
The repository for a command line / build pipeline tool for generating colors from a human-readable text file that designers can also use.

ColorPaletteGenerator ColorPaletteGenerator is a tool that takes a human-readable input file describing a color palette, and generates the associated

horseshoe7 0 Dec 7, 2021