Skip to content

Commit 3074d77

Browse files
committed
Add Button.highlighted
1 parent 2b944ca commit 3074d77

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Few-iOS/Button.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,20 @@ public class Button: Element {
1717
public var imageForState: (UIControlState -> UIImage?)
1818
public var enabled: Bool
1919
public var selected: Bool
20+
public var highlighted: Bool
2021

2122
private var trampoline = TargetActionTrampoline()
2223

23-
public convenience init(attributedTitle: NSAttributedString, image: UIImage? = nil, enabled: Bool = true, selected: Bool = false, action: (() -> Void) = { }) {
24-
self.init(attributedTitleForState: {_ in attributedTitle}, imageForState: {_ in image}, enabled: enabled, selected: selected, action: {_ in action() })
24+
public convenience init(attributedTitle: NSAttributedString, image: UIImage? = nil, action: (() -> Void) = { }) {
25+
self.init(attributedTitleForState: {_ in attributedTitle}, imageForState: {_ in image}, action: {_ in action() })
2526
}
2627

27-
public init(attributedTitleForState: (UIControlState -> NSAttributedString?), imageForState: (UIControlState -> UIImage?) = {_ in nil}, enabled: Bool = true, selected: Bool = false, action: (() -> Void) = { }) {
28+
public init(attributedTitleForState: (UIControlState -> NSAttributedString?), imageForState: (UIControlState -> UIImage?) = {_ in nil}, enabled: Bool = true, selected: Bool = false, highlighted: Bool = false, action: (() -> Void) = { }) {
2829
self.imageForState = imageForState
2930
self.attributedTitleForState = attributedTitleForState
3031
self.selected = selected
3132
self.enabled = enabled
33+
self.highlighted = highlighted
3234
trampoline.action = action
3335
super.init(frame: CGRect(x: 0, y: 0, width: 50, height: 23))
3436
}
@@ -52,6 +54,10 @@ public class Button: Element {
5254
if selected != button.selected {
5355
button.selected = selected
5456
}
57+
58+
if highlighted != button.highlighted {
59+
button.highlighted = highlighted
60+
}
5561

5662
for state in UIControlState.all {
5763
let newImage = imageForState(state)
@@ -77,6 +83,7 @@ public class Button: Element {
7783
button.hidden = hidden
7884
button.enabled = enabled
7985
button.selected = selected
86+
button.highlighted = highlighted
8087
button.addTarget(trampoline, action: trampoline.selector, forControlEvents: .TouchUpInside)
8188
return button
8289
}

0 commit comments

Comments
 (0)