on master help sign in
Add value property
f42ed5bGunay Mert Karadogan
GMStepper/GMStepper/GMStepper.swift+13−2
@@ -9,6 +9,16 @@
9import UIKit
9import UIKit
10
10
11class GMStepper: UIView {
11class GMStepper: UIView {
12+ var value = 0 {
13+ didSet {
14+ value = min(maximumValue, max(minimumValue, value))
15+ label.text = String(value)
16+ }
17+ }
18+
19+ var minimumValue = 0
20+ var maximumValue = 10
21+
12 let leftButton = UIButton()
22 let leftButton = UIButton()
13 let rightButton = UIButton()
23 let rightButton = UIButton()
14 let label = UILabel()
24 let label = UILabel()
@@ -26,6 +36,7 @@ class GMStepper: UIView {
26 rightButton.addTarget(self, action: "rightButtonTapped:", forControlEvents: .TouchDown)
36 rightButton.addTarget(self, action: "rightButtonTapped:", forControlEvents: .TouchDown)
27
37
28 label.textAlignment = .Center
38 label.textAlignment = .Center
39+ label.text = String(value)
29
40
30 addSubview(leftButton)
41 addSubview(leftButton)
31 addSubview(rightButton)
42 addSubview(rightButton)
@@ -46,10 +57,10 @@ class GMStepper: UIView {
46 }
57 }
47
58
48 func leftButtonTapped(button: UIButton) {
59 func leftButtonTapped(button: UIButton) {
49−
60+ value -= 1
50 }
61 }
51
62
52 func rightButtonTapped(button: UIButton) {
63 func rightButtonTapped(button: UIButton) {
53−
64+ value += 1
54 }
65 }
55}
66}