Updated 2 February 2021
UIBezierPath() – A Bezier Path that consists of straight and curved line segments that you can render in your custom views. and we can say that to use of Bezier Path curve we can make effective UIViews with so many designs which make our UIDesign is more attractive
I used a specific view shape, on this concept you learn that how can be applied to any shape. This example shows the process of designing the shape which you want to draw it on a view.
UIBezierPath() – We can use this method to make different views like chat-bubble and shapes.
How to draw a BezierPath Curve in a custom view
Main steps of the curve:
CGPoint:
The CG point of the curve is a geometric structure. or we can say, A structure that consists of a point with a two-dimensional coordinates system i.e x and y.
example: CGPoint(x: 0.0, y: 0.0)
toPoint:The end
point of the curve
controlPoint1:
First control point to use when computing the curve.
controlPoint2:
Second control point to use when computing the curve.Here we have a bezierPath code of the above example in which we can make our view.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import Foundation import UIKit class BrezerPath: UIView{ override func draw(_ rect: CGRect) { let bezierPath = UIBezierPath() bezierPath.move(to: CGPoint(x: rect.maxX+5, y: rect.minY))//a bezierPath.addLine(to: CGPoint(x: rect.maxX, y: rect.minY))//b bezierPath.addLine(to: CGPoint(x: rect.maxX-10, y: 10))//c bezierPath.addLine(to: CGPoint(x: rect.maxX-10, y: rect.maxY-5))//d bezierPath.addQuadCurve(to: CGPoint(x: rect.maxX-15, y: rect.maxY), controlPoint: CGPoint(x: rect.maxX-10, y: rect.maxY)) bezierPath.addLine(to: CGPoint(x: rect.maxX-15, y: rect.maxY))//e bezierPath.addLine(to: CGPoint(x:rect.minX+5, y:rect.maxY))//f bezierPath.addQuadCurve(to: CGPoint(x: rect.minX, y: rect.maxY-5), controlPoint: CGPoint(x: rect.minX, y: rect.maxY)) bezierPath.addLine(to: CGPoint(x: rect.minX, y: rect.maxY-5))//g bezierPath.addLine(to: CGPoint(x: rect.minX, y: rect.minY+5))//h bezierPath.addQuadCurve(to: CGPoint(x: rect.minX+5, y: rect.minY), controlPoint: CGPoint(x: rect.minX, y: rect.minY)) bezierPath.addLine(to: CGPoint(x: rect.minX+5, y: rect.minY))//i UIColor.blue.setFill() bezierPath.fill() bezierPath.close() } } |
Take view in the view controller and change view class name of the view to your bezierPath.swift class
Here we have the final output in our simulator.
In this blog, we have discussed how to draw a custom view or custom shape by using BezierPath curve.
I hope this blog will help you in getting some basic knowledge about the BezierPath curve
Thanks for reading!
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.