This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func getRightEyeShape() -> CAShapeLayer { | |
let rightEyeWrapPath = UIBezierPath() | |
rightEyeWrapPath.move(to: CGPoint(x: 392, y: 165)) | |
rightEyeWrapPath.addCurve(to: CGPoint(x: 317, y: 175), | |
controlPoint1: CGPoint(x: 400, y: 200), | |
controlPoint2: CGPoint(x: 330, y: 230)) | |
let eyePath = UIBezierPath() | |
eyePath.move(to: CGPoint(x: 345, y: 135)) | |
eyePath.addQuadCurve(to: CGPoint(x: 350, y: 155), | |
controlPoint: CGPoint(x: 320, y: 150)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func getMouthShape() -> CAShapeLayer { | |
let path = UIBezierPath() | |
path.move(to: CGPoint(x: 310, y: 250)) | |
path.addCurve(to: CGPoint(x: 175, y: 250), | |
controlPoint1: CGPoint(x: 330, y: 335), | |
controlPoint2: CGPoint(x: 125, y: 325)) | |
path.addCurve(to: CGPoint(x: 310, y: 250), | |
controlPoint1: CGPoint(x: 195, y: 245), | |
controlPoint2: CGPoint(x: 260, y: 265)) | |
let mouthShape = CAShapeLayer() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func getHeadShape() -> CAShapeLayer { | |
let path = UIBezierPath() | |
path.move(to: CGPoint(x: 84, y: 196)) //Set StartPoint for QuadCurve | |
path.addQuadCurve(to: CGPoint(x: 366, y: 100), //Add EndPoint QuadCurve and StartPoint for Curve | |
controlPoint: CGPoint(x: 205, y: 100)) | |
path.addCurve(to: CGPoint(x: 84, y: 196), //Add EndPoint for Curve | |
controlPoint1: CGPoint(x: 500, y: 330), | |
controlPoint2: CGPoint(x: 120, y: 430)) | |
path.close() //Connect first point and last point of bezier path | |
let headShape = CAShapeLayer() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CupheadView.swift | |
// UIBezierPathLesson | |
// | |
// Created by Alexander Nikolaychuk on 12.06.2020. | |
// Copyright © 2020 AlexAlmostEngineer. All rights reserved. | |
// | |
import UIKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Paths Part | |
let rect = UIBezierPath(rect: CGRect(x: 50, y: 50, width: 50, height: 50)) | |
let oval = UIBezierPath(ovalIn: CGRect(x: 120, y: 120, width: 100, height: 50)) | |
let roundedRect = UIBezierPath(roundedRect: CGRect(x: 200, y: 200, width: 50, height: 50), | |
cornerRadius: 10.0) | |
//Shapes | |
let rectShape = CAShapeLayer() | |
rectShape.path = rect.cgPath | |
rectShape.lineWidth = 4.0 | |
rectShape.fillColor = UIColor.clear.cgColor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Path Part | |
let path = UIBezierPath() | |
path.move(to: CGPoint(x: 50, y: 200)) | |
path.addCurve(to: CGPoint(x: 200, y: 200), | |
controlPoint1: CGPoint(x: 80, y: 300), | |
controlPoint2: CGPoint(x: 150, y: 0)) | |
//Shape Part | |
let shape = CAShapeLayer() | |
shape.path = path.cgPath | |
shape.lineWidth = 4.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Path part | |
let path = UIBezierPath() | |
path.move(to: CGPoint(x: 50, y: 50)) | |
path.addQuadCurve(to: CGPoint(x: 200, y: 50), | |
controlPoint: CGPoint(x: 100, y: 200)) | |
//Shape part | |
let shape = CAShapeLayer() | |
shape.path = path.cgPath | |
shape.lineWidth = 4.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Path part | |
let path = UIBezierPath() | |
path.move(to: CGPoint(x: 200, y: 200)) //StartPoint | |
path.addLine(to: CGPoint(x: 380, y: 380)) //EndPoint of First Line and StartPoint for Second Line | |
path.addLine(to: CGPoint(x: 20, y: 380)) //EndPoint of Second Line | |
//Shape part | |
let shape = CAShapeLayer() | |
shape.path = path.cgPath | |
shape.lineWidth = 4.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func getSegment(startAngle: Radians, | |
endInAngle: Radians, | |
color: UIColor, | |
strokeEnd: CGFloat) -> CAShapeLayer { | |
let centre = CGPoint(x: bounds.width / 2, y: bounds.height / 2) //Center of drawing | |
let beizerPath = UIBezierPath(arcCenter: centre, | |
radius: bounds.height / 2 - settings.segmentWidth / 2, //Segment width | |
startAngle: startAngle, //Start angle in radians (0 for example) | |
endAngle: endInAngle, //End angle in radians (pi / 2 for example) | |
clockwise: true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
typealias Degrees = Double | |
typealias Radians = CGFloat | |
//Structure for custom indicator settings | |
struct ANSegmentIndicatorSettings { | |
var segmentsCount: Int = 4 | |
var segmentWidth: CGFloat = 2 | |
var spaceBetweenSegments: Degrees = 10 |