@@ -98,9 +98,9 @@ public var KeyboardButtonPopupViewTag: Int = 101
98
98
public var KeyboardButtonMenuViewTag : Int = 102
99
99
100
100
public class KeyboardButton : UIView {
101
- public var type : KeyboardButtonType = . Key( " " )
102
- public var widthInRow : KeyboardButtonWidth = . Dynamic
103
- public var style : KeyboardButtonStyle !
101
+ public var type : KeyboardButtonType = . Key( " " ) { didSet { reload ( ) } }
102
+ public var widthInRow : KeyboardButtonWidth = . Dynamic { didSet { reload ( ) } }
103
+ public var style : KeyboardButtonStyle ! { didSet { reload ( ) } }
104
104
public var keyMenu : KeyMenu ?
105
105
106
106
public var textLabel : UILabel ?
@@ -122,8 +122,39 @@ public class KeyboardButton: UIView {
122
122
self . style = style
123
123
self . widthInRow = width
124
124
self . identifier = identifier
125
+ reload ( )
126
+ }
127
+
128
+ public required init ? ( coder aDecoder: NSCoder ) {
129
+ super. init ( coder: aDecoder)
130
+ reload ( )
131
+ }
132
+
133
+ private func reload( ) {
125
134
userInteractionEnabled = true
126
- setupAppearance ( )
135
+ backgroundColor = style. backgroundColor
136
+ layer. cornerRadius = style. cornerRadius
137
+
138
+ // border
139
+ layer. borderColor = style. borderColor. CGColor
140
+ layer. borderWidth = style. borderWidth
141
+
142
+ // shadow
143
+ if style. shadowEnabled {
144
+ layer. shadowColor = style. shadowColor. CGColor
145
+ layer. shadowOpacity = style. shadowOpacity
146
+ layer. shadowOffset = style. shadowOffset
147
+ layer. shadowRadius = style. shadowRadius
148
+ if let path = style. shadowPath {
149
+ layer. shadowPath = path. CGPath
150
+ }
151
+ }
152
+
153
+ // content
154
+ textLabel? . removeFromSuperview ( )
155
+ textLabel = nil
156
+ imageView? . removeFromSuperview ( )
157
+ imageView = nil
127
158
128
159
switch type {
129
160
case . Key( let text) :
@@ -153,28 +184,6 @@ public class KeyboardButton: UIView {
153
184
}
154
185
}
155
186
156
- public required init ? ( coder aDecoder: NSCoder ) {
157
- super. init ( coder: aDecoder)
158
- }
159
-
160
- private func setupAppearance( ) {
161
- backgroundColor = style. backgroundColor
162
- layer. cornerRadius = style. cornerRadius
163
- // border
164
- layer. borderColor = style. borderColor. CGColor
165
- layer. borderWidth = style. borderWidth
166
- // shadow
167
- if style. shadowEnabled {
168
- layer. shadowColor = style. shadowColor. CGColor
169
- layer. shadowOpacity = style. shadowOpacity
170
- layer. shadowOffset = style. shadowOffset
171
- layer. shadowRadius = style. shadowRadius
172
- if let path = style. shadowPath {
173
- layer. shadowPath = path. CGPath
174
- }
175
- }
176
- }
177
-
178
187
// MARK: Layout
179
188
public override func layoutSubviews( ) {
180
189
super. layoutSubviews ( )
0 commit comments