@@ -8,29 +8,28 @@
88
99import UIKit
1010
11−class GMStepper: UIView {
12− var value = 0 {
11+public class GMStepper: UIView {
12+ public var value = 0 {
1313 didSet {
1414 value = min(maximumValue, max(minimumValue, value))
1515 label.text = String(value)
1616 }
1717 }
1818
19− var minimumValue = 0
20− var maximumValue = 10
19+ public var minimumValue = 0
2120
22− let leftButton = UIButton()
23− let rightButton = UIButton()
24− let label = UILabel()
21+ public var maximumValue = 10
2522
26− required init(coder aDecoder: NSCoder) {
23+
24+ private let leftButton = UIButton()
25+ private let rightButton = UIButton()
26+ private let label = UILabel()
27+
28+ required public init(coder aDecoder: NSCoder) {
2729 super.init(coder: aDecoder)
28−
29− let leftButtonImage = UIImage(named: "minus")
30− let rightButtonImage = UIImage(named: "plus")
3130
32− rightButton.setImage(rightButtonImage, forState: [.Normal])
33− leftButton.setImage(leftButtonImage, forState: [.Normal])
31+ leftButton.setTitle("-", forState: [.Normal])
32+ rightButton.setTitle("+", forState: [.Normal])
3433
3534 leftButton.addTarget(self, action: "leftButtonTapped:", forControlEvents: .TouchDown)
3635 rightButton.addTarget(self, action: "rightButtonTapped:", forControlEvents: .TouchDown)
@@ -41,26 +40,27 @@ class GMStepper: UIView {
4140 addSubview(leftButton)
4241 addSubview(rightButton)
4342 addSubview(label)
43+
44+ backgroundColor = UIColor.grayColor()
45+ label.backgroundColor = UIColor.redColor()
46+ leftButton.backgroundColor = UIColor.purpleColor()
47+ rightButton.backgroundColor = UIColor.purpleColor()
4448 }
4549
46− override func layoutSubviews() {
47− let buttonSize = Int(frame.size.height)
48− let labelWidth = Int(frame.size.width) - 2 * buttonSize
49−
50− let leftButtonFrame = CGRect(x: 0, y: 0, width: buttonSize, height: buttonSize)
51− let labelFrame = CGRect(x: buttonSize, y: 0, width: labelWidth, height: buttonSize)
52− let rightButtonFrame = CGRect(x: buttonSize + labelWidth, y: 0, width: buttonSize, height: buttonSize)
50+ public override func layoutSubviews() {
51+ let buttonWidth = bounds.size.width * 0.25
52+ let labelWidth = bounds.size.width * 0.5
5353
54− leftButton.frame = leftButtonFrame
55− label.frame = labelFrame
56− rightButton.frame = rightButtonFrame
54+ leftButton.frame = CGRect(x: 0, y: 0, width: buttonWidth, height: bounds.size.height)
55+ label.frame = CGRect(x: buttonWidth, y: 0, width: labelWidth, height: bounds.size.height)
56+ rightButton.frame = CGRect(x: labelWidth + buttonWidth, y: 0, width: buttonWidth, height: bounds.size.height)
5757 }
5858
59− func leftButtonTapped(button: UIButton) {
59+ private func leftButtonTapped(button: UIButton) {
6060 value -= 1
6161 }
6262
63− func rightButtonTapped(button: UIButton) {
63+ private func rightButtonTapped(button: UIButton) {
6464 value += 1
6565 }
6666}