Maybe you need to draw an arrow or a chevron but don’t want to do a rasterized image. This code is also autolayout compatible.
Here’s some Swift 3.0 code for drawing a chevron so that you can easily write some code like this:

1
2
3
let arrow = Arrow(frame: CGRect(x: 0, y: 0, width: 400, height: 400))
arrow.lineWidth = 20
arrow.lineColor = UIColor.blue

Then get something like:

Core Graphics Chevron

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class Arrow  : UIView {

enum Direction {
case up, down, left, right
}

var direction : Direction = Direction.right {
didSet {
review()
}
}

var lineColor = UIColor.red {
didSet {
review()
}
}

var lineWidth : CGFloat = 20 {
didSet {
review()
}
}

func review(){
setNeedsDisplay()
}


static func directionToRadians(_ direction: Arrow.Direction) -> CGFloat{
switch direction {
case .up:
return Arrow.degreesToRadians(90)
case .down:
return Arrow.degreesToRadians(-90)
case .left:
return Arrow.degreesToRadians(0)
case .right:
return Arrow.degreesToRadians(180)
}
}

static func degreesToRadians(_ degrees: CGFloat) -> CGFloat {
return degrees * CGFloat(M_PI) / 180
}

override func draw(_ rect: CGRect) {
let origin = CGPoint(x: 12, y: self.frame.height / 2)
let path = UIBezierPath()
path.lineJoinStyle = CGLineJoin.round
path.move(to: CGPoint(x: origin.x + self.frame.width * (1/2), y: frame.height - 10))
path.addLine(to: CGPoint(x: origin.x, y: origin.y))
path.addLine(to: CGPoint(x: origin.x + self.frame.width * (1/2), y: 10))
lineColor.set()
path.lineWidth = lineWidth
path.stroke()
self.backgroundColor = UIColor.clear
self.transform = CGAffineTransform(rotationAngle: Arrow.directionToRadians(self.direction))
}
}

Credits

Thanks to @Dondragmer from this StackOverflow’s Answer