-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTSView.swift
More file actions
111 lines (92 loc) · 2.64 KB
/
TSView.swift
File metadata and controls
111 lines (92 loc) · 2.64 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
// TSView.swift
// Finja
//
// Created by Tallha Sarwar on 24/12/2019.
// Copyright © 2019 Finja Pvt Limited. All rights reserved.
//
import Foundation
@IBDesignable class TSView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
sharedInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
sharedInit()
}
override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
sharedInit()
}
func sharedInit() {
refreshCorners(value: cornerRadius)
refreshshadowColor(value: shadowColor)
refreshshadowRadius(value: shadowRadius)
refreshshadowOpacity(value: shadowOpacity)
refreshshadowOffsetY(value: shadowOffsetY)
refreshBorderWidth(value: borderWidth)
}
@IBInspectable var cornerRadius: CGFloat = 0 {
didSet {
if !rounded {
refreshCorners(value: cornerRadius)
}
}
}
@IBInspectable public var rounded: Bool = false {
didSet {
if rounded {
cornerRadius = frame.height/2
refreshCorners(value: cornerRadius)
}
else{
refreshCorners(value: cornerRadius)
}
}
}
func refreshCorners(value: CGFloat) {
layer.cornerRadius = value
layoutIfNeeded()
}
@IBInspectable public var shadowColor: UIColor = UIColor.clear {
didSet {
refreshshadowColor(value: shadowColor)
}
}
func refreshshadowColor(value: UIColor) {
layer.shadowColor = value.cgColor
}
@IBInspectable public var shadowRadius: CGFloat = 0 {
didSet {
refreshshadowRadius(value: shadowRadius)
}
}
func refreshshadowRadius(value: CGFloat) {
layer.shadowRadius = value
}
@IBInspectable public var borderWidth: CGFloat = 0 {
didSet {
refreshBorderWidth(value: borderWidth)
}
}
func refreshBorderWidth(value: CGFloat) {
layer.borderWidth = value
}
@IBInspectable public var shadowOpacity: CGFloat = 0 {
didSet {
refreshshadowOpacity(value: shadowOpacity)
}
}
func refreshshadowOpacity(value: CGFloat) {
layer.shadowOpacity = Float(value)
}
@IBInspectable public var shadowOffsetY: CGFloat = 0 {
didSet {
refreshshadowOffsetY(value: shadowOffsetY)
}
}
func refreshshadowOffsetY(value: CGFloat) {
layer.shadowOffset.height = value
}
}