on master help sign in
Add IBDesignable and IBInspectable
43199a7Gunay Mert Karadogan
GMStepper/GMStepper/Base.lproj/Main.storyboard+10−2
@@ -21,9 +21,17 @@
21 <rect key="frame" x="20" y="20" width="284" height="44"/>
21 <rect key="frame" x="20" y="20" width="284" height="44"/>
22 <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
22 <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
23 <constraints>
23 <constraints>
24− <constraint firstAttribute="width" constant="284" id="RLe-7a-S9I"/>
24+ <constraint firstAttribute="width" constant="284" id="CF0-ce-PHQ"/>
25− <constraint firstAttribute="height" constant="44" id="bMh-qb-O1H"/>
25+ <constraint firstAttribute="height" constant="44" id="mzJ-k6-SLm"/>
26 </constraints>
26 </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>
27 </view>
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"/>
GMStepper/GMStepper/GMStepper.swift+68−15
@@ -8,7 +8,7 @@
8
8
9import UIKit
9import UIKit
10
10
11−public class GMStepper: UIControl {
11+@IBDesignable public class GMStepper: UIControl {
12 public 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))
@@ -20,23 +20,71 @@ public class GMStepper: UIControl {
20 }
20 }
21 }
21 }
22
22
23− public var minimumValue = 0
23+ @IBInspectable public var minimumValue: Int = 0 {
24− public var maximumValue = 10
24+ didSet {
25+ value = 0
26+ }
27+ }
25
28
26− public var leftButtonText = "-"
29+ @IBInspectable public var maximumValue: Int = 10 {
27− public var rightButtonText = "+"
30+ didSet {
31+ value = 0
32+ }
33+ }
28
34
29− public var buttonsTextColor = UIColor.whiteColor()
35+ @IBInspectable public var leftButtonText: String = "-" {
36+ didSet {
37+ leftButton.setTitle(leftButtonText, forState: [.Normal])
38+ }
39+ }
30
40
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+
31− public var buttonsBackgroundColor = UIColor(red:0.21, green:0.5, blue:0.74, alpha:1)
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+ }
32
62
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+ }
34
70
35− public var labelTextColor = UIColor.whiteColor()
71+ @IBInspectable public var labelTextColor: UIColor = UIColor.whiteColor() {
72+ didSet {
73+ label.textColor = labelTextColor
74+ }
75+ }
36
76
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+ }
38
82
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+ }
40
88
41 private let leftButton = UIButton()
89 private let leftButton = UIButton()
42 private let rightButton = UIButton()
90 private let rightButton = UIButton()
@@ -44,7 +92,15 @@ public class GMStepper: UIControl {
44
92
45 required public init(coder aDecoder: NSCoder) {
93 required public init(coder aDecoder: NSCoder) {
46 super.init(coder: aDecoder)
94 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() {
48 leftButton.setTitle(leftButtonText, forState: [.Normal])
104 leftButton.setTitle(leftButtonText, forState: [.Normal])
49 leftButton.setTitleColor(buttonsTextColor, forState: [.Normal])
105 leftButton.setTitleColor(buttonsTextColor, forState: [.Normal])
50 leftButton.backgroundColor = buttonsBackgroundColor
106 leftButton.backgroundColor = buttonsBackgroundColor
@@ -65,9 +121,6 @@ public class GMStepper: UIControl {
65 label.backgroundColor = labelBackgroundColor
121 label.backgroundColor = labelBackgroundColor
66 label.font = labelFont
122 label.font = labelFont
67 addSubview(label)
123 addSubview(label)
68−
69− backgroundColor = UIColor.grayColor()
70−
71 }
124 }
72
125
73 public override func layoutSubviews() {
126 public override func layoutSubviews() {