@@ -8,29 +8,28 @@
9import UIKit
9import UIKit
11−class GMStepper: UIView {
11+public class GMStepper: UIView {
12− var value = 0 {
12+ public var value = 0 {
14 value = min(maximumValue, max(minimumValue, value))
14 value = min(maximumValue, max(minimumValue, value))
15 label.text = String(value)
15 label.text = String(value)
19− var minimumValue = 0
19+ public var minimumValue = 0
20− var maximumValue = 10
22− let leftButton = UIButton()
21+ public var maximumValue = 10
23− let rightButton = UIButton()
24− let label = UILabel()
24+ private let leftButton = UIButton()
25+ private let rightButton = UIButton()
26+ private let label = UILabel()
26− required init(coder aDecoder: NSCoder) {
28+ required public init(coder aDecoder: NSCoder) {
27 super.init(coder: aDecoder)
29 super.init(coder: aDecoder)
29− let leftButtonImage = UIImage(named: "minus")
30− let rightButtonImage = UIImage(named: "plus")
32− rightButton.setImage(rightButtonImage, forState: [.Normal])
31+ leftButton.setTitle("-", forState: [.Normal])
33− leftButton.setImage(leftButtonImage, forState: [.Normal])
32+ rightButton.setTitle("+", forState: [.Normal])
35 leftButton.addTarget(self, action: "leftButtonTapped:", forControlEvents: .TouchDown)
34 leftButton.addTarget(self, action: "leftButtonTapped:", forControlEvents: .TouchDown)
36 rightButton.addTarget(self, action: "rightButtonTapped:", forControlEvents: .TouchDown)
35 rightButton.addTarget(self, action: "rightButtonTapped:", forControlEvents: .TouchDown)
@@ -41,26 +40,27 @@ class GMStepper: UIView {
41 addSubview(leftButton)
40 addSubview(leftButton)
42 addSubview(rightButton)
41 addSubview(rightButton)
43 addSubview(label)
42 addSubview(label)
44+ backgroundColor = UIColor.grayColor()
45+ label.backgroundColor = UIColor.redColor()
46+ leftButton.backgroundColor = UIColor.purpleColor()
47+ rightButton.backgroundColor = UIColor.purpleColor()
46− override func layoutSubviews() {
50+ public override func layoutSubviews() {
47− let buttonSize = Int(frame.size.height)
51+ let buttonWidth = bounds.size.width * 0.25
48− let labelWidth = Int(frame.size.width) - 2 * buttonSize
52+ let labelWidth = bounds.size.width * 0.5
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)
54− leftButton.frame = leftButtonFrame
54+ leftButton.frame = CGRect(x: 0, y: 0, width: buttonWidth, height: bounds.size.height)
55− label.frame = labelFrame
55+ label.frame = CGRect(x: buttonWidth, y: 0, width: labelWidth, height: bounds.size.height)
56− rightButton.frame = rightButtonFrame
56+ rightButton.frame = CGRect(x: labelWidth + buttonWidth, y: 0, width: buttonWidth, height: bounds.size.height)
59− func leftButtonTapped(button: UIButton) {
59+ private func leftButtonTapped(button: UIButton) {
60 value -= 1
60 value -= 1
63− func rightButtonTapped(button: UIButton) {
63+ private func rightButtonTapped(button: UIButton) {
64 value += 1
64 value += 1