Skip to content

Commit 8746cc7

Browse files
committed
[KeyboardButtonStyle] Add shadowEnabled property
Easier shadow on/off mechanism instead of assigning nil every shadow property of `KeyboardButtonStyle`. Podspec version number bumped.
1 parent b33cda6 commit 8746cc7

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

Keyboard/DefaultKeyboard/DefaultKeyboardLayout.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public var DefaultKeyboardChildRowStyle = KeyboardRowStyle(
3232
buttonsPadding: 6)
3333

3434
// MARK: - Button Style
35+
public var DefaultKeyboardKeyButtonStyle = KeyboardButtonStyle(showsPopup: true)
36+
3537
public var DefaultKeyboardSpaceButtonStyle = KeyboardButtonStyle(
3638
font: UIFont.systemFontOfSize(15),
3739
showsPopup: false)
@@ -61,8 +63,6 @@ public var DefaultKeyboardNumbersButtonStyle = KeyboardButtonStyle(
6163
font: UIFont.systemFontOfSize(15),
6264
showsPopup: false)
6365

64-
public var DefaultKeyboardKeyButtonStyle = KeyboardButtonStyle(showsPopup: true)
65-
6666
// MARK: - Identifier
6767
public enum DefaultKeyboardIdentifier: String {
6868
case Space = "Space"

Keyboard/KeyboardLayoutEngine/KeyboardButton.swift

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public struct KeyboardButtonStyle {
3232
public var borderWidth: CGFloat
3333

3434
// Shadow
35+
public var shadowEnabled: Bool
3536
public var shadowColor: UIColor
3637
public var shadowOpacity: Float
3738
public var shadowOffset: CGSize
@@ -55,6 +56,7 @@ public struct KeyboardButtonStyle {
5556
cornerRadius: CGFloat = 5,
5657
borderColor: UIColor = UIColor.clearColor(),
5758
borderWidth: CGFloat = 0,
59+
shadowEnabled: Bool = true,
5860
shadowColor: UIColor = UIColor.blackColor(),
5961
shadowOpacity: Float = 0.4,
6062
shadowOffset: CGSize = CGSize(width: 0, height: 1),
@@ -70,6 +72,7 @@ public struct KeyboardButtonStyle {
7072
self.cornerRadius = cornerRadius
7173
self.borderColor = borderColor
7274
self.borderWidth = borderWidth
75+
self.shadowEnabled = shadowEnabled
7376
self.shadowColor = shadowColor
7477
self.shadowOpacity = shadowOpacity
7578
self.shadowOffset = shadowOffset
@@ -148,14 +151,18 @@ public class KeyboardButton: UIView {
148151
private func setupAppearance() {
149152
backgroundColor = style.backgroundColor
150153
layer.cornerRadius = style.cornerRadius
154+
// border
151155
layer.borderColor = style.borderColor.CGColor
152156
layer.borderWidth = style.borderWidth
153-
layer.shadowColor = style.shadowColor.CGColor
154-
layer.shadowOpacity = style.shadowOpacity
155-
layer.shadowOffset = style.shadowOffset
156-
layer.shadowRadius = style.shadowRadius
157-
if let path = style.shadowPath {
158-
layer.shadowPath = path.CGPath
157+
// shadow
158+
if style.shadowEnabled {
159+
layer.shadowColor = style.shadowColor.CGColor
160+
layer.shadowOpacity = style.shadowOpacity
161+
layer.shadowOffset = style.shadowOffset
162+
layer.shadowRadius = style.shadowRadius
163+
if let path = style.shadowPath {
164+
layer.shadowPath = path.CGPath
165+
}
159166
}
160167
}
161168

@@ -183,12 +190,12 @@ public class KeyboardButton: UIView {
183190
// MARK: Popup
184191
private func showPopup(show show: Bool) {
185192
if show {
186-
if viewWithTag(1) != nil { return }
193+
if viewWithTag(101) != nil { return }
187194
let popup = createPopup()
188-
popup.tag = 1
195+
popup.tag = 101
189196
addSubview(popup)
190197
} else {
191-
if let popup = viewWithTag(1) {
198+
if let popup = viewWithTag(101) {
192199
popup.removeFromSuperview()
193200
}
194201
}

KeyboardLayoutEngine.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616
#
1717

1818
s.name = "KeyboardLayoutEngine"
19-
s.version = "0.4"
19+
s.version = "0.5"
2020
s.summary = "⌨️ Simplest custom keyboard generator for iOS ever!"
2121

2222
# This description is used to generate tags and improve search results.
@@ -336,7 +336,7 @@ optional func defaultKeyboardDidPressReturnButton(defaultKeyboard: DefaultKeyboa
336336
# Supports git, hg, bzr, svn and HTTP.
337337
#
338338

339-
s.source = { :git => "https://github.com/cemolcay/KeyboardLayoutEngine.git", :tag => "0.4" }
339+
s.source = { :git => "https://github.com/cemolcay/KeyboardLayoutEngine.git", :tag => "0.5" }
340340

341341

342342
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

0 commit comments

Comments
 (0)