on master help sign in
Add IBDesignable and IBInspectable
commit43199a72db08659378ca6e090b3709ea9e924098 authorGunay Mert Karadogan <mertkaradogan@gmail.com> dateWed 1 Jul 2015, 18:51 (11 years ago) parenta4bb70d
2 files changed+78−17
GMStepper/GMStepper/Base.lproj/Main.storyboard+10−2 GMStepper/GMStepper/GMStepper.swift+68−15
GMStepper/GMStepper/Base.lproj/Main.storyboard+10−2
@@ -21,9 +21,17 @@
2121 <rect key="frame" x="20" y="20" width="284" height="44"/>
2222 <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
2323 <constraints>
24− <constraint firstAttribute="width" constant="284" id="RLe-7a-S9I"/>
25− <constraint firstAttribute="height" constant="44" id="bMh-qb-O1H"/>
24+ <constraint firstAttribute="width" constant="284" id="CF0-ce-PHQ"/>
25+ <constraint firstAttribute="height" constant="44" id="mzJ-k6-SLm"/>
2626 </constraints>
27+ <userDefinedRuntimeAttributes>
28+ <userDefinedRuntimeAttribute type="number" keyPath="minimumValue">
29+ <integer key="value" value="0"/>
30+ </userDefinedRuntimeAttribute>
31+ <userDefinedRuntimeAttribute type="number" keyPath="maximumValue">
32+ <integer key="value" value="9"/>
33+ </userDefinedRuntimeAttribute>
34+ </userDefinedRuntimeAttributes>
2735 </view>
2836 </subviews>
2937 <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
GMStepper/GMStepper/GMStepper.swift+68−15
@@ -8,7 +8,7 @@
88
99import UIKit
1010
11−public class GMStepper: UIControl {
11+@IBDesignable public class GMStepper: UIControl {
1212 public var value = 0 {
1313 didSet {
1414 value = min(maximumValue, max(minimumValue, value))
@@ -20,23 +20,71 @@ public class GMStepper: UIControl {
2020 }
2121 }
2222
23− public var minimumValue = 0
24− public var maximumValue = 10
23+ @IBInspectable public var minimumValue: Int = 0 {
24+ didSet {
25+ value = 0
26+ }
27+ }
2528
26− public var leftButtonText = "-"
27− public var rightButtonText = "+"
29+ @IBInspectable public var maximumValue: Int = 10 {
30+ didSet {
31+ value = 0
32+ }
33+ }
2834
29− public var buttonsTextColor = UIColor.whiteColor()
35+ @IBInspectable public var leftButtonText: String = "-" {
36+ didSet {
37+ leftButton.setTitle(leftButtonText, forState: [.Normal])
38+ }
39+ }
3040
31− public var buttonsBackgroundColor = UIColor(red:0.21, green:0.5, blue:0.74, alpha:1)
41+ @IBInspectable public var rightButtonText: String = "+" {
42+ didSet {
43+ rightButton.setTitle(rightButtonText, forState: [.Normal])
44+ }
45+ }
46+
47+ @IBInspectable public var buttonsTextColor: UIColor = UIColor.whiteColor() {
48+ didSet {
49+ for button in [leftButton, rightButton] {
50+ button.setTitleColor(buttonsTextColor, forState: [.Normal])
51+ }
52+ }
53+ }
54+
55+ @IBInspectable public var buttonsBackgroundColor: UIColor = UIColor(red:0.21, green:0.5, blue:0.74, alpha:1) {
56+ didSet {
57+ for button in [leftButton, rightButton] {
58+ button.backgroundColor = buttonsBackgroundColor
59+ }
60+ }
61+ }
3262
33− public var buttonsFont = UIFont(name: "AvenirNext-Bold", size: 20.0)!
63+ public var buttonsFont = UIFont(name: "AvenirNext-Bold", size: 20.0)! {
64+ didSet {
65+ for button in [leftButton, rightButton] {
66+ button.titleLabel?.font = buttonsFont
67+ }
68+ }
69+ }
3470
35− public var labelTextColor = UIColor.whiteColor()
71+ @IBInspectable public var labelTextColor: UIColor = UIColor.whiteColor() {
72+ didSet {
73+ label.textColor = labelTextColor
74+ }
75+ }
3676
37− public var labelBackgroundColor = UIColor(red:0.26, green:0.6, blue:0.87, alpha:1)
77+ @IBInspectable public var labelBackgroundColor: UIColor = UIColor(red:0.26, green:0.6, blue:0.87, alpha:1) {
78+ didSet {
79+ label.backgroundColor = labelBackgroundColor
80+ }
81+ }
3882
39− public var labelFont = UIFont(name: "AvenirNext-Bold", size: 25.0)!
83+ public var labelFont = UIFont(name: "AvenirNext-Bold", size: 25.0)! {
84+ didSet {
85+ label.font = labelFont
86+ }
87+ }
4088
4189 private let leftButton = UIButton()
4290 private let rightButton = UIButton()
@@ -44,7 +92,15 @@ public class GMStepper: UIControl {
4492
4593 required public init(coder aDecoder: NSCoder) {
4694 super.init(coder: aDecoder)
47−
95+ setup()
96+ }
97+
98+ public override init(frame: CGRect) {
99+ super.init(frame: frame)
100+ setup()
101+ }
102+
103+ private func setup() {
48104 leftButton.setTitle(leftButtonText, forState: [.Normal])
49105 leftButton.setTitleColor(buttonsTextColor, forState: [.Normal])
50106 leftButton.backgroundColor = buttonsBackgroundColor
@@ -65,9 +121,6 @@ public class GMStepper: UIControl {
65121 label.backgroundColor = labelBackgroundColor
66122 label.font = labelFont
67123 addSubview(label)
68−
69− backgroundColor = UIColor.grayColor()
70−
71124 }
72125
73126 public override func layoutSubviews() {