on master help sign in
6 files changed+74−40
since splitsnapshots
unifiedsplit
.swift-version+1−1 GMStepper.podspec+2−2 GMStepper/GMStepper.swift+40−28 GMStepperExample/GMStepperExample.xcodeproj/project.pbxproj+23−6 GMStepperExample/GMStepperExample/ViewController.swift+1−1 README.md+7−2
.swift-version+1−1
@@ -1 +1 @@
1−3.0
1+4.0
GMStepper.podspec+2−2
@@ -1,9 +1,9 @@
11Pod::Spec.new do |s|
22 s.name = "GMStepper"
3− s.version = "2.0.0"
3+ s.version = "2.1"
44 s.summary = "A stepper with a sliding label in the middle."
55 s.homepage = "https://github.com/gmertk/GMStepper"
6− s.screenshots = "https://dl.dropboxusercontent.com/u/4397140/pod-screenshots/screenshot_1.png"
6+ s.screenshots = "https://raw.githubusercontent.com/gmertk/GMStepper/master/Screenshots/screenshot_1.gif"
77 s.license = 'MIT'
88 s.author = { "Gunay Mert Karadogan" => "mertkaradogan@gmail.com" }
99 s.source = { :git => "https://github.com/gmertk/GMStepper.git", :tag => s.version.to_s }
GMStepper/GMStepper.swift+40−28
@@ -11,7 +11,7 @@ import UIKit
1111@IBDesignable public class GMStepper: UIControl {
1212
1313 /// Current value of the stepper. Defaults to 0.
14− @IBInspectable public var value: Double = 0 {
14+ @objc @IBInspectable public var value: Double = 0 {
1515 didSet {
1616 value = min(maximumValue, max(minimumValue, value))
1717
@@ -37,44 +37,44 @@ import UIKit
3737 }
3838
3939 /// Minimum value. Must be less than maximumValue. Defaults to 0.
40− @IBInspectable public var minimumValue: Double = 0 {
40+ @objc @IBInspectable public var minimumValue: Double = 0 {
4141 didSet {
4242 value = min(maximumValue, max(minimumValue, value))
4343 }
4444 }
4545
4646 /// Maximum value. Must be more than minimumValue. Defaults to 100.
47− @IBInspectable public var maximumValue: Double = 100 {
47+ @objc @IBInspectable public var maximumValue: Double = 100 {
4848 didSet {
4949 value = min(maximumValue, max(minimumValue, value))
5050 }
5151 }
5252
5353 /// Step/Increment value as in UIStepper. Defaults to 1.
54− @IBInspectable public var stepValue: Double = 1
54+ @objc @IBInspectable public var stepValue: Double = 1
5555
5656 /// The same as UIStepper's autorepeat. If true, holding on the buttons or keeping the pan gesture alters the value repeatedly. Defaults to true.
57− @IBInspectable public var autorepeat: Bool = true
57+ @objc @IBInspectable public var autorepeat: Bool = true
5858
5959 /// If the value is integer, it is shown without floating point.
60− @IBInspectable public var showIntegerIfDoubleIsInteger: Bool = true
60+ @objc @IBInspectable public var showIntegerIfDoubleIsInteger: Bool = true
6161
6262 /// Text on the left button. Be sure that it fits in the button. Defaults to "−".
63− @IBInspectable public var leftButtonText: String = "−" {
63+ @objc @IBInspectable public var leftButtonText: String = "−" {
6464 didSet {
6565 leftButton.setTitle(leftButtonText, for: .normal)
6666 }
6767 }
6868
6969 /// Text on the right button. Be sure that it fits in the button. Defaults to "+".
70− @IBInspectable public var rightButtonText: String = "+" {
70+ @objc @IBInspectable public var rightButtonText: String = "+" {
7171 didSet {
7272 rightButton.setTitle(rightButtonText, for: .normal)
7373 }
7474 }
7575
7676 /// Text color of the buttons. Defaults to white.
77− @IBInspectable public var buttonsTextColor: UIColor = UIColor.white {
77+ @objc @IBInspectable public var buttonsTextColor: UIColor = UIColor.white {
7878 didSet {
7979 for button in [leftButton, rightButton] {
8080 button.setTitleColor(buttonsTextColor, for: .normal)
@@ -83,7 +83,7 @@ import UIKit
8383 }
8484
8585 /// Background color of the buttons. Defaults to dark blue.
86− @IBInspectable public var buttonsBackgroundColor: UIColor = UIColor(red:0.21, green:0.5, blue:0.74, alpha:1) {
86+ @objc @IBInspectable public var buttonsBackgroundColor: UIColor = UIColor(red:0.21, green:0.5, blue:0.74, alpha:1) {
8787 didSet {
8888 for button in [leftButton, rightButton] {
8989 button.backgroundColor = buttonsBackgroundColor
@@ -93,7 +93,7 @@ import UIKit
9393 }
9494
9595 /// Font of the buttons. Defaults to AvenirNext-Bold, 20.0 points in size.
96− public var buttonsFont = UIFont(name: "AvenirNext-Bold", size: 20.0)! {
96+ @objc public var buttonsFont = UIFont(name: "AvenirNext-Bold", size: 20.0)! {
9797 didSet {
9898 for button in [leftButton, rightButton] {
9999 button.titleLabel?.font = buttonsFont
@@ -102,28 +102,35 @@ import UIKit
102102 }
103103
104104 /// Text color of the middle label. Defaults to white.
105− @IBInspectable public var labelTextColor: UIColor = UIColor.white {
105+ @objc @IBInspectable public var labelTextColor: UIColor = UIColor.white {
106106 didSet {
107107 label.textColor = labelTextColor
108108 }
109109 }
110110
111111 /// Text color of the middle label. Defaults to lighter blue.
112− @IBInspectable public var labelBackgroundColor: UIColor = UIColor(red:0.26, green:0.6, blue:0.87, alpha:1) {
112+ @objc @IBInspectable public var labelBackgroundColor: UIColor = UIColor(red:0.26, green:0.6, blue:0.87, alpha:1) {
113113 didSet {
114114 label.backgroundColor = labelBackgroundColor
115115 }
116116 }
117117
118118 /// Font of the middle label. Defaults to AvenirNext-Bold, 25.0 points in size.
119− public var labelFont = UIFont(name: "AvenirNext-Bold", size: 25.0)! {
119+ @objc public var labelFont = UIFont(name: "AvenirNext-Bold", size: 25.0)! {
120120 didSet {
121121 label.font = labelFont
122122 }
123123 }
124+ /// Corner radius of the middle label. Defaults to 0.
125+ @objc @IBInspectable public var labelCornerRadius: CGFloat = 0 {
126+ didSet {
127+ label.layer.cornerRadius = labelCornerRadius
128+
129+ }
130+ }
124131
125132 /// Corner radius of the stepper's layer. Defaults to 4.0.
126− @IBInspectable public var cornerRadius: CGFloat = 4.0 {
133+ @objc @IBInspectable public var cornerRadius: CGFloat = 4.0 {
127134 didSet {
128135 layer.cornerRadius = cornerRadius
129136 clipsToBounds = true
@@ -131,7 +138,7 @@ import UIKit
131138 }
132139
133140 /// Border width of the stepper and middle label's layer. Defaults to 0.0.
134− @IBInspectable public var borderWidth: CGFloat = 0.0 {
141+ @objc @IBInspectable public var borderWidth: CGFloat = 0.0 {
135142 didSet {
136143 layer.borderWidth = borderWidth
137144 label.layer.borderWidth = borderWidth
@@ -139,7 +146,7 @@ import UIKit
139146 }
140147
141148 /// Color of the border of the stepper and middle label's layer. Defaults to clear color.
142− @IBInspectable public var borderColor: UIColor = UIColor.clear {
149+ @objc @IBInspectable public var borderColor: UIColor = UIColor.clear {
143150 didSet {
144151 layer.borderColor = borderColor.cgColor
145152 label.layer.borderColor = borderColor.cgColor
@@ -147,7 +154,7 @@ import UIKit
147154 }
148155
149156 /// Percentage of the middle label's width. Must be between 0 and 1. Defaults to 0.5. Be sure that it is wide enough to show the value.
150− @IBInspectable public var labelWidthWeight: CGFloat = 0.5 {
157+ @objc @IBInspectable public var labelWidthWeight: CGFloat = 0.5 {
151158 didSet {
152159 labelWidthWeight = min(1, max(0, labelWidthWeight))
153160 setNeedsLayout()
@@ -155,7 +162,7 @@ import UIKit
155162 }
156163
157164 /// Color of the flashing animation on the buttons in case the value hit the limit.
158− @IBInspectable public var limitHitAnimationColor: UIColor = UIColor(red:0.26, green:0.6, blue:0.87, alpha:1)
165+ @objc @IBInspectable public var limitHitAnimationColor: UIColor = UIColor(red:0.26, green:0.6, blue:0.87, alpha:1)
159166
160167 /**
161168 Width of the sliding animation. When buttons clicked, the middle label does a slide animation towards to the clicked button. Defaults to 5.
@@ -177,6 +184,7 @@ import UIKit
177184 button.addTarget(self, action: #selector(GMStepper.leftButtonTouchDown), for: .touchDown)
178185 button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchUpInside)
179186 button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchUpOutside)
187+ button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchCancel)
180188 return button
181189 }()
182190
@@ -189,6 +197,7 @@ import UIKit
189197 button.addTarget(self, action: #selector(GMStepper.rightButtonTouchDown), for: .touchDown)
190198 button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchUpInside)
191199 button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchUpOutside)
200+ button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchCancel)
192201 return button
193202 }()
194203
@@ -203,6 +212,8 @@ import UIKit
203212 label.textColor = self.labelTextColor
204213 label.backgroundColor = self.labelBackgroundColor
205214 label.font = self.labelFont
215+ label.layer.cornerRadius = self.labelCornerRadius
216+ label.layer.masksToBounds = true
206217 label.isUserInteractionEnabled = true
207218 let panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(GMStepper.handlePan))
208219 panRecognizer.maximumNumberOfTouches = 1
@@ -234,7 +245,7 @@ import UIKit
234245 }
235246
236247
237− public var items : [String] = [] {
248+ @objc public var items : [String] = [] {
238249 didSet {
239250 let isInteger = floor(value) == value
240251
@@ -280,12 +291,12 @@ import UIKit
280291 }
281292 }
282293
283− required public init?(coder aDecoder: NSCoder) {
294+ @objc required public init?(coder aDecoder: NSCoder) {
284295 super.init(coder: aDecoder)
285296 setup()
286297 }
287298
288− public override init(frame: CGRect) {
299+ @objc public override init(frame: CGRect) {
289300 super.init(frame: frame)
290301 setup()
291302 }
@@ -298,6 +309,7 @@ import UIKit
298309 backgroundColor = buttonsBackgroundColor
299310 layer.cornerRadius = cornerRadius
300311 clipsToBounds = true
312+ labelOriginalCenter = label.center
301313
302314 NotificationCenter.default.addObserver(self, selector: #selector(GMStepper.reset), name: NSNotification.Name.UIApplicationWillResignActive, object: nil)
303315 }
@@ -344,7 +356,7 @@ import UIKit
344356
345357// MARK: Pan Gesture
346358extension GMStepper {
347− func handlePan(gesture: UIPanGestureRecognizer) {
359+ @objc func handlePan(gesture: UIPanGestureRecognizer) {
348360 switch gesture.state {
349361 case .began:
350362 leftButton.isEnabled = false
@@ -394,7 +406,7 @@ extension GMStepper {
394406 }
395407 }
396408
397− func reset() {
409+ @objc func reset() {
398410 panState = .Stable
399411 stepperState = .Stable
400412 resetTimer()
@@ -413,7 +425,7 @@ extension GMStepper {
413425
414426// MARK: Button Events
415427extension GMStepper {
416− func leftButtonTouchDown(button: UIButton) {
428+ @objc func leftButtonTouchDown(button: UIButton) {
417429 rightButton.isEnabled = false
418430 label.isUserInteractionEnabled = false
419431 resetTimer()
@@ -427,7 +439,7 @@ extension GMStepper {
427439
428440 }
429441
430− func rightButtonTouchDown(button: UIButton) {
442+ @objc func rightButtonTouchDown(button: UIButton) {
431443 leftButton.isEnabled = false
432444 label.isUserInteractionEnabled = false
433445 resetTimer()
@@ -440,7 +452,7 @@ extension GMStepper {
440452 }
441453 }
442454
443− func buttonTouchUp(button: UIButton) {
455+ @objc func buttonTouchUp(button: UIButton) {
444456 reset()
445457 }
446458}
@@ -485,7 +497,7 @@ extension GMStepper {
485497
486498// MARK: Timer
487499extension GMStepper {
488− func handleTimerFire(timer: Timer) {
500+ @objc func handleTimerFire(timer: Timer) {
489501 timerFireCount += 1
490502
491503 if timerFireCount % timerFireCountModulo == 0 {
GMStepperExample/GMStepperExample.xcodeproj/project.pbxproj+23−6
@@ -163,18 +163,19 @@
163163 attributes = {
164164 LastSwiftMigration = 0700;
165165 LastSwiftUpdateCheck = 0800;
166− LastUpgradeCheck = 0800;
166+ LastUpgradeCheck = 0900;
167167 ORGANIZATIONNAME = "Gunay Mert Karadogan";
168168 TargetAttributes = {
169169 3116C0D71DA4DD360015AC69 = {
170170 CreatedOnToolsVersion = 8.0;
171+ LastSwiftMigration = 0900;
171172 ProvisioningStyle = Automatic;
172173 TestTargetID = 319C19311B4843EB005EFEE5;
173174 };
174175 319C19311B4843EB005EFEE5 = {
175176 CreatedOnToolsVersion = 6.4;
176177 DevelopmentTeam = 289M6XEDV4;
177− LastSwiftMigration = 0800;
178+ LastSwiftMigration = 0900;
178179 };
179180 };
180181 };
@@ -281,7 +282,8 @@
281282 PRODUCT_BUNDLE_IDENTIFIER = com.gmertk.GMStepperExampleTests;
282283 PRODUCT_NAME = "$(TARGET_NAME)";
283284 SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
284− SWIFT_VERSION = 3.0;
285+ SWIFT_SWIFT3_OBJC_INFERENCE = On;
286+ SWIFT_VERSION = 4.0;
285287 TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GMStepperExample.app/GMStepperExample";
286288 };
287289 name = Debug;
@@ -298,7 +300,8 @@
298300 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
299301 PRODUCT_BUNDLE_IDENTIFIER = com.gmertk.GMStepperExampleTests;
300302 PRODUCT_NAME = "$(TARGET_NAME)";
301− SWIFT_VERSION = 3.0;
303+ SWIFT_SWIFT3_OBJC_INFERENCE = On;
304+ SWIFT_VERSION = 4.0;
302305 TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GMStepperExample.app/GMStepperExample";
303306 };
304307 name = Release;
@@ -311,14 +314,20 @@
311314 CLANG_CXX_LIBRARY = "libc++";
312315 CLANG_ENABLE_MODULES = YES;
313316 CLANG_ENABLE_OBJC_ARC = YES;
317+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
314318 CLANG_WARN_BOOL_CONVERSION = YES;
319+ CLANG_WARN_COMMA = YES;
315320 CLANG_WARN_CONSTANT_CONVERSION = YES;
316321 CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
317322 CLANG_WARN_EMPTY_BODY = YES;
318323 CLANG_WARN_ENUM_CONVERSION = YES;
319324 CLANG_WARN_INFINITE_RECURSION = YES;
320325 CLANG_WARN_INT_CONVERSION = YES;
326+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
327+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
321328 CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
329+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
330+ CLANG_WARN_STRICT_PROTOTYPES = YES;
322331 CLANG_WARN_SUSPICIOUS_MOVE = YES;
323332 CLANG_WARN_UNREACHABLE_CODE = YES;
324333 CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -358,14 +367,20 @@
358367 CLANG_CXX_LIBRARY = "libc++";
359368 CLANG_ENABLE_MODULES = YES;
360369 CLANG_ENABLE_OBJC_ARC = YES;
370+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
361371 CLANG_WARN_BOOL_CONVERSION = YES;
372+ CLANG_WARN_COMMA = YES;
362373 CLANG_WARN_CONSTANT_CONVERSION = YES;
363374 CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
364375 CLANG_WARN_EMPTY_BODY = YES;
365376 CLANG_WARN_ENUM_CONVERSION = YES;
366377 CLANG_WARN_INFINITE_RECURSION = YES;
367378 CLANG_WARN_INT_CONVERSION = YES;
379+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
380+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
368381 CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
382+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
383+ CLANG_WARN_STRICT_PROTOTYPES = YES;
369384 CLANG_WARN_SUSPICIOUS_MOVE = YES;
370385 CLANG_WARN_UNREACHABLE_CODE = YES;
371386 CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -399,7 +414,8 @@
399414 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
400415 PRODUCT_BUNDLE_IDENTIFIER = "com.gunaymert.$(PRODUCT_NAME:rfc1034identifier)";
401416 PRODUCT_NAME = "$(TARGET_NAME)";
402− SWIFT_VERSION = 3.0;
417+ SWIFT_SWIFT3_OBJC_INFERENCE = Default;
418+ SWIFT_VERSION = 4.0;
403419 };
404420 name = Debug;
405421 };
@@ -412,7 +428,8 @@
412428 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
413429 PRODUCT_BUNDLE_IDENTIFIER = "com.gunaymert.$(PRODUCT_NAME:rfc1034identifier)";
414430 PRODUCT_NAME = "$(TARGET_NAME)";
415− SWIFT_VERSION = 3.0;
431+ SWIFT_SWIFT3_OBJC_INFERENCE = Default;
432+ SWIFT_VERSION = 4.0;
416433 };
417434 name = Release;
418435 };
GMStepperExample/GMStepperExample/ViewController.swift+1−1
@@ -16,7 +16,7 @@ class ViewController: UIViewController {
1616 stepper.addTarget(self, action: #selector(ViewController.stepperValueChanged), for: .valueChanged)
1717 }
1818
19− func stepperValueChanged(stepper: GMStepper) {
19+ @objc func stepperValueChanged(stepper: GMStepper) {
2020 print(stepper.value, terminator: "")
2121 }
2222}
README.md+7−2
@@ -5,6 +5,7 @@
55
66A stepper with a sliding label in the middle. Pan the label or tap the buttons. Check out the tutorial, [How to Build a Custom Stepper - Part 1](http://gmertk.github.io/custom-stepper-part-1/).
77
8+
89## Screenshot
910
1011![Screenshot_1.gif](https://raw.githubusercontent.com/gmertk/GMStepper/master/Screenshots/screenshot_1.gif)
@@ -68,6 +69,9 @@ var labelBackgroundColor: UIColor = UIColor(red:0.26, green:0.6, blue:0.87, alph
6869/// Font of the middle label. Defaults to AvenirNext-Bold, 25.0 points in size.
6970var labelFont = UIFont(name: "AvenirNext-Bold", size: 25.0)
7071
72+/// Corner radius of the middle label's layer. Defaults to 0.0.
73+var labelCornerRadius: CGFloat = 0.0
74+
7175/// Corner radius of the stepper's layer. Defaults to 4.0.
7276var cornerRadius: CGFloat = 4.0
7377
@@ -85,9 +89,10 @@ var limitHitAnimationColor: UIColor = UIColor(red:0.26, green:0.6, blue:0.87, al
8589```
8690
8791
88−## Author
92+## Authors
8993
90−Günay Mert Karadoğan, mertkaradogan@gmail.com
94+* [Brent Whitman](https://github.com/bwhtmn) - Maintainer
95+* [Günay Mert Karadoğan](https://github.com/gmertk) - Creator
9196
9297## License
9398