-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBLLine.swift
74 lines (49 loc) · 1.63 KB
/
BLLine.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
//
// BLLine.swift
// fourshaonian
//
// Created by FangYan on 16/5/26.
// Copyright © 2016年 yousi.inc. All rights reserved.
//
import UIKit
@IBDesignable
public class BLLine: UIView {
@IBInspectable var borderColor : UIColor = UIColor.grayColor(){
didSet {
reDraw()
}
}
@IBInspectable var borderWidth : CGFloat = 0.5 {
didSet {
reDraw()
}
}
@IBInspectable var ifVertical : Bool = false {
didSet {
reDraw()
}
}
override public func drawRect(rect: CGRect) {
self.backgroundColor = UIColor.clearColor()
let context:CGContextRef = UIGraphicsGetCurrentContext()!;//上下文
CGContextSaveGState(context);
CGContextSetAllowsAntialiasing(context, true) //抗锯齿设置
let frame = self.layer.bounds
let p1:CGMutablePathRef = CGPathCreateMutable();
if ifVertical {
CGPathMoveToPoint(p1, nil, 0, 0)
CGPathAddLineToPoint(p1, nil, 0, frame.height)
} else {
CGPathMoveToPoint(p1, nil, 0, 0)
CGPathAddLineToPoint(p1, nil, frame.width , 0)
}
CGPathCloseSubpath(p1);
CGContextAddPath(context, p1)
CGContextSetLineWidth(context, borderWidth)
CGContextSetStrokeColorWithColor(context, borderColor.CGColor)
CGContextStrokePath(context)
CGContextRestoreGState(context)
}
func reDraw (){
}
}