-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIPrimitives.swift
77 lines (60 loc) · 2.76 KB
/
UIPrimitives.swift
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
public class UIPrimitives{
public class func drawOval(#width: CGFloat, height: CGFloat, fillColor: UIColor = UIColor.redColor(), strokeSize: CGFloat = 0, strokeColor: UIColor = UIColor.clearColor(), rotation: CGFloat = 0) {
//// General Declarations
let context = UIGraphicsGetCurrentContext()
//// Oval Drawing
CGContextSaveGState(context)
if rotation != 0{
CGContextRotateCTM(context, -rotation * CGFloat(M_PI) / 180)
}
var ovalPath = UIBezierPath(ovalInRect: CGRectMake(-width/2, -height/2, width, height))
fillColor.setFill()
ovalPath.fill()
if strokeSize != 0 {
strokeColor.setStroke()
ovalPath.lineWidth = strokeSize
ovalPath.stroke()
}
CGContextRestoreGState(context)
}
public class func drawRectangle(#width: CGFloat, height: CGFloat, cornerRadius:CGFloat = 0, fillColor: UIColor = UIColor.redColor(), strokeSize: CGFloat = 0, strokeColor: UIColor = UIColor.clearColor(), rotation: CGFloat = 0) {
//// General Declarations
let context = UIGraphicsGetCurrentContext()
//// Rectangle 2 Drawing
CGContextSaveGState(context)
if rotation != 0{
CGContextRotateCTM(context, -rotation * CGFloat(M_PI) / 180)
}
let rectangle2Path = UIBezierPath(roundedRect: CGRectMake(-width/2, -height/2, width, height), cornerRadius: cornerRadius)
fillColor.setFill()
rectangle2Path.fill()
if strokeSize != 0 {
strokeColor.setStroke()
rectangle2Path.lineWidth = strokeSize
rectangle2Path.stroke()
}
CGContextRestoreGState(context)
}
public class func drawTriangle(#width: CGFloat, height: CGFloat, fillColor: UIColor = UIColor.redColor(), strokeSize: CGFloat = 0, strokeColor: UIColor = UIColor.clearColor(), rotation: CGFloat = 0) {
//// General Declarations
let context = UIGraphicsGetCurrentContext()
//// Polygon Drawing
CGContextSaveGState(context)
if rotation != 0{
CGContextRotateCTM(context, -rotation * CGFloat(M_PI) / 180)
}
var trianglePath = UIBezierPath()
trianglePath.moveToPoint(CGPointMake(-width/2, 0))
trianglePath.addLineToPoint(CGPointMake(-width, -height))
trianglePath.addLineToPoint(CGPointMake(0, -height))
trianglePath.closePath()
fillColor.setFill()
trianglePath.fill()
if strokeSize != 0 {
strokeColor.setStroke()
trianglePath.lineWidth = strokeSize
trianglePath.stroke()
}
CGContextRestoreGState(context)
}
}