on master help sign in
Remove plus/minus images and add access modifiers
commit3978cf78787198d8ea540b7e50cd3c24207d9452 authorGunay Mert Karadogan <mertkaradogan@gmail.com> dateWed 1 Jul 2015, 16:55 (11 years ago) parentf42ed5b
2 files changed+33−25
GMStepper/GMStepper/Base.lproj/Main.storyboard+8 GMStepper/GMStepper/GMStepper.swift+25−25
GMStepper/GMStepper/Base.lproj/Main.storyboard+8
@@ -25,6 +25,14 @@
2525 <constraint firstAttribute="height" constant="44" id="bMh-qb-O1H"/>
2626 </constraints>
2727 </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>
2836 </subviews>
2937 <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
3038 <constraints>
GMStepper/GMStepper/GMStepper.swift+25−25
@@ -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}