-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUIView+Extension.swift
63 lines (57 loc) · 1.52 KB
/
UIView+Extension.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
//
// UIView+Extension.swift
// Shoaib
//
// Created by Shoaib Sarwar Cheema on 25/02/2016.
// Copyright © 2016. All rights reserved.
//
import UIKit
@IBDesignable extension UIView {
@IBInspectable var borderColor:UIColor? {
set {
layer.borderColor = newValue!.cgColor
}
get {
if let color = layer.borderColor {
return UIColor(cgColor:color)
}
else {
return nil
}
}
}
@IBInspectable var borderWidth:CGFloat {
set {
layer.borderWidth = newValue
}
get {
return layer.borderWidth
}
}
@IBInspectable var cornerRadius:CGFloat {
set {
layer.cornerRadius = newValue
clipsToBounds = newValue > 0
}
get {
return layer.cornerRadius
}
}
@IBInspectable var padding:CGFloat {
set {
self.bounds = self.frame.insetBy(dx: padding, dy: padding);
}
get {
return self.bounds.origin.x
}
}
class func loadFromNibNamed(_ nibNamed: String, bundle : Bundle? = nil,owner: AnyObject) -> UIView? {
return UINib(
nibName: nibNamed,
bundle: bundle
).instantiate(withOwner: owner, options: nil)[0] as? UIView
}
func addBorder(_ edge: UIRectEdge, color: UIColor, thickness: CGFloat) {
self.layer.addBorder(edge, color: color, thickness: thickness)
}
}