on master help sign in
Remove plus/minus images and add access modifiers
3978cf7Gunay Mert Karadogan
GMStepper/GMStepper/Base.lproj/Main.storyboard+8
@@ -25,6 +25,14 @@
25 <constraint firstAttribute="height" constant="44" id="bMh-qb-O1H"/>
25 <constraint firstAttribute="height" constant="44" id="bMh-qb-O1H"/>
26 </constraints>
26 </constraints>
27 </view>
27 </view>
28+ <view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="LHM-6l-lrt" customClass="GMStepper" customModule="GMStepper" customModuleProvider="target">
29+ <rect key="frame" x="20" y="323" width="391" height="209"/>
30+ <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
31+ </view>
32+ <view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="rA3-ct-Qsh" customClass="GMStepper" customModule="GMStepper" customModuleProvider="target">
33+ <rect key="frame" x="20" y="129" width="240" height="128"/>
34+ <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
35+ </view>
28 </subviews>
36 </subviews>
29 <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
37 <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
30 <constraints>
38 <constraints>
GMStepper/GMStepper/GMStepper.swift+25−25
@@ -8,29 +8,28 @@
8
8
9import UIKit
9import UIKit
10
10
11−class GMStepper: UIView {
11+public class GMStepper: UIView {
12− var value = 0 {
12+ public var value = 0 {
13 didSet {
13 didSet {
14 value = min(maximumValue, max(minimumValue, value))
14 value = min(maximumValue, max(minimumValue, value))
15 label.text = String(value)
15 label.text = String(value)
16 }
16 }
17 }
17 }
18
18
19− var minimumValue = 0
19+ public var minimumValue = 0
20− var maximumValue = 10
21
20
22− let leftButton = UIButton()
21+ public var maximumValue = 10
23− let rightButton = UIButton()
24− let label = UILabel()
25
22
23+
24+ private let leftButton = UIButton()
25+ private let rightButton = UIButton()
26+ private let label = UILabel()
27+
26− required init(coder aDecoder: NSCoder) {
28+ required public init(coder aDecoder: NSCoder) {
27 super.init(coder: aDecoder)
29 super.init(coder: aDecoder)
28−
29− let leftButtonImage = UIImage(named: "minus")
30− let rightButtonImage = UIImage(named: "plus")
31
30
32− rightButton.setImage(rightButtonImage, forState: [.Normal])
31+ leftButton.setTitle("-", forState: [.Normal])
33− leftButton.setImage(leftButtonImage, forState: [.Normal])
32+ rightButton.setTitle("+", forState: [.Normal])
34
33
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)
43+
44+ backgroundColor = UIColor.grayColor()
45+ label.backgroundColor = UIColor.redColor()
46+ leftButton.backgroundColor = UIColor.purpleColor()
47+ rightButton.backgroundColor = UIColor.purpleColor()
44 }
48 }
45
49
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
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)
53
53
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)
57 }
57 }
58
58
59− func leftButtonTapped(button: UIButton) {
59+ private func leftButtonTapped(button: UIButton) {
60 value -= 1
60 value -= 1
61 }
61 }
62
62
63− func rightButtonTapped(button: UIButton) {
63+ private func rightButtonTapped(button: UIButton) {
64 value += 1
64 value += 1
65 }
65 }
66}
66}