on master help sign in
7 files changed+58−69
since splitsnapshots
unifiedsplit
.swift-version+1−1 GMStepper.podspec+3−4 GMStepper/GMStepper.swift+42−48 GMStepperExample/GMStepperExample.xcodeproj/project.pbxproj+10−6 GMStepperExample/GMStepperExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist−8 GMStepperExample/GMStepperExample/AppDelegate.swift+1−1 GMStepperExample/GMStepperExample/Base.lproj/Main.storyboard+1−1
.swift-version+1−1
@@ -1 +1 @@
1−4.2
1+4.0
GMStepper.podspec+3−4
@@ -1,15 +1,14 @@
11Pod::Spec.new do |s|
22 s.name = "GMStepper"
3− s.version = "2.2"
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"
66 s.screenshots = "https://raw.githubusercontent.com/gmertk/GMStepper/master/Screenshots/screenshot_1.gif"
77 s.license = 'MIT'
8− s.authors = { "Gunay Mert Karadogan" => "mertkaradogan@gmail.com",
9− "Brent Whitman" => "brent@pathym.com" }
8+ s.author = { "Gunay Mert Karadogan" => "mertkaradogan@gmail.com" }
109 s.source = { :git => "https://github.com/gmertk/GMStepper.git", :tag => s.version.to_s }
1110 s.social_media_url = 'https://twitter.com/gunaymertk'
12− s.platform = :ios, '8.4'
11+ s.platform = :ios, '8.0'
1312 s.requires_arc = true
1413 s.source_files = 'GMStepper/*.swift'
1514end
GMStepper/GMStepper.swift+42−48
@@ -15,26 +15,26 @@ import UIKit
1515 didSet {
1616 value = min(maximumValue, max(minimumValue, value))
1717
18− label.text = formattedValue
18+ let isInteger = floor(value) == value
19+
20+ //
21+ // If we have items, we will display them as steps
22+ //
23+
24+ if isInteger && stepValue == 1.0 && items.count > 0 {
25+ label.text = items[Int(value)]
26+ }
27+ else if showIntegerIfDoubleIsInteger && isInteger {
28+ label.text = String(stringInterpolationSegment: Int(value))
29+ } else {
30+ label.text = String(stringInterpolationSegment: value)
31+ }
1932
2033 if oldValue != value {
2134 sendActions(for: .valueChanged)
2235 }
2336 }
2437 }
25−
26− private var formattedValue: String? {
27− let isInteger = Decimal(value).exponent >= 0
28−
29− // If we have items, we will display them as steps
30− if isInteger && stepValue == 1.0 && items.count > 0 {
31− return items[Int(value)]
32− }
33− else {
34− return formatter.string(from: NSNumber(value: value))
35− }
36− }
37−
3838
3939 /// Minimum value. Must be less than maximumValue. Defaults to 0.
4040 @objc @IBInspectable public var minimumValue: Double = 0 {
@@ -51,21 +51,13 @@ import UIKit
5151 }
5252
5353 /// Step/Increment value as in UIStepper. Defaults to 1.
54− @objc @IBInspectable public var stepValue: Double = 1 {
55− didSet {
56− setupNumberFormatter()
57− }
58− }
54+ @objc @IBInspectable public var stepValue: Double = 1
5955
6056 /// The same as UIStepper's autorepeat. If true, holding on the buttons or keeping the pan gesture alters the value repeatedly. Defaults to true.
6157 @objc @IBInspectable public var autorepeat: Bool = true
6258
6359 /// If the value is integer, it is shown without floating point.
64− @objc @IBInspectable public var showIntegerIfDoubleIsInteger: Bool = true {
65− didSet {
66− setupNumberFormatter()
67− }
68− }
60+ @objc @IBInspectable public var showIntegerIfDoubleIsInteger: Bool = true
6961
7062 /// Text on the left button. Be sure that it fits in the button. Defaults to "−".
7163 @objc @IBInspectable public var leftButtonText: String = "−" {
@@ -172,9 +164,6 @@ import UIKit
172164 /// Color of the flashing animation on the buttons in case the value hit the limit.
173165 @objc @IBInspectable public var limitHitAnimationColor: UIColor = UIColor(red:0.26, green:0.6, blue:0.87, alpha:1)
174166
175− /// Formatter for displaying the current value
176− let formatter = NumberFormatter()
177−
178167 /**
179168 Width of the sliding animation. When buttons clicked, the middle label does a slide animation towards to the clicked button. Defaults to 5.
180169 */
@@ -215,7 +204,11 @@ import UIKit
215204 lazy var label: UILabel = {
216205 let label = UILabel()
217206 label.textAlignment = .center
218− label.text = formattedValue
207+ if self.showIntegerIfDoubleIsInteger && floor(self.value) == self.value {
208+ label.text = String(stringInterpolationSegment: Int(self.value))
209+ } else {
210+ label.text = String(stringInterpolationSegment: self.value)
211+ }
219212 label.textColor = self.labelTextColor
220213 label.backgroundColor = self.labelBackgroundColor
221214 label.font = self.labelFont
@@ -254,7 +247,24 @@ import UIKit
254247
255248 @objc public var items : [String] = [] {
256249 didSet {
257− label.text = formattedValue
250+ let isInteger = floor(value) == value
251+
252+ //
253+ // If we have items, we will display them as steps
254+ //
255+
256+ if isInteger && stepValue == 1.0 && items.count > 0 {
257+
258+ var value = Int(self.value)
259+
260+ if value >= items.count {
261+ value = items.count - 1
262+ self.value = Double(value)
263+ }
264+ else {
265+ label.text = items[value]
266+ }
267+ }
258268 }
259269 }
260270
@@ -291,7 +301,7 @@ import UIKit
291301 setup()
292302 }
293303
294− fileprivate func setup() {
304+ func setup() {
295305 addSubview(leftButton)
296306 addSubview(rightButton)
297307 addSubview(label)
@@ -301,17 +311,7 @@ import UIKit
301311 clipsToBounds = true
302312 labelOriginalCenter = label.center
303313
304− setupNumberFormatter()
305−
306− NotificationCenter.default.addObserver(self, selector: #selector(GMStepper.reset), name: UIApplication.willResignActiveNotification, object: nil)
307− }
308−
309− func setupNumberFormatter() {
310− let decValue = Decimal(stepValue)
311− let digits = decValue.significantFractionalDecimalDigits
312− formatter.minimumIntegerDigits = 1
313− formatter.minimumFractionDigits = showIntegerIfDoubleIsInteger ? 0 : digits
314− formatter.maximumFractionDigits = digits
314+ NotificationCenter.default.addObserver(self, selector: #selector(GMStepper.reset), name: NSNotification.Name.UIApplicationWillResignActive, object: nil)
315315 }
316316
317317 public override func layoutSubviews() {
@@ -332,9 +332,8 @@ import UIKit
332332 value += stepValue
333333 } else if stepperState == .ShouldDecrease {
334334 value -= stepValue
335− }
335+ }
336336 }
337−
338337
339338 deinit {
340339 resetTimer()
@@ -517,11 +516,6 @@ extension GMStepper {
517516 timerFireCount = 0
518517 }
519518 }
520−}
521519
522520
523−extension Decimal {
524− var significantFractionalDecimalDigits: Int {
525− return max(-exponent, 0)
526− }
527521}
GMStepperExample/GMStepperExample.xcodeproj/project.pbxproj+10−6
@@ -168,14 +168,14 @@
168168 TargetAttributes = {
169169 3116C0D71DA4DD360015AC69 = {
170170 CreatedOnToolsVersion = 8.0;
171− LastSwiftMigration = 1000;
171+ LastSwiftMigration = 0900;
172172 ProvisioningStyle = Automatic;
173173 TestTargetID = 319C19311B4843EB005EFEE5;
174174 };
175175 319C19311B4843EB005EFEE5 = {
176176 CreatedOnToolsVersion = 6.4;
177177 DevelopmentTeam = 289M6XEDV4;
178− LastSwiftMigration = 1000;
178+ LastSwiftMigration = 0900;
179179 };
180180 };
181181 };
@@ -282,7 +282,8 @@
282282 PRODUCT_BUNDLE_IDENTIFIER = com.gmertk.GMStepperExampleTests;
283283 PRODUCT_NAME = "$(TARGET_NAME)";
284284 SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
285− SWIFT_VERSION = 4.2;
285+ SWIFT_SWIFT3_OBJC_INFERENCE = On;
286+ SWIFT_VERSION = 4.0;
286287 TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GMStepperExample.app/GMStepperExample";
287288 };
288289 name = Debug;
@@ -299,7 +300,8 @@
299300 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
300301 PRODUCT_BUNDLE_IDENTIFIER = com.gmertk.GMStepperExampleTests;
301302 PRODUCT_NAME = "$(TARGET_NAME)";
302− SWIFT_VERSION = 4.2;
303+ SWIFT_SWIFT3_OBJC_INFERENCE = On;
304+ SWIFT_VERSION = 4.0;
303305 TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GMStepperExample.app/GMStepperExample";
304306 };
305307 name = Release;
@@ -412,7 +414,8 @@
412414 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
413415 PRODUCT_BUNDLE_IDENTIFIER = "com.gunaymert.$(PRODUCT_NAME:rfc1034identifier)";
414416 PRODUCT_NAME = "$(TARGET_NAME)";
415− SWIFT_VERSION = 4.2;
417+ SWIFT_SWIFT3_OBJC_INFERENCE = Default;
418+ SWIFT_VERSION = 4.0;
416419 };
417420 name = Debug;
418421 };
@@ -425,7 +428,8 @@
425428 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
426429 PRODUCT_BUNDLE_IDENTIFIER = "com.gunaymert.$(PRODUCT_NAME:rfc1034identifier)";
427430 PRODUCT_NAME = "$(TARGET_NAME)";
428− SWIFT_VERSION = 4.2;
431+ SWIFT_SWIFT3_OBJC_INFERENCE = Default;
432+ SWIFT_VERSION = 4.0;
429433 };
430434 name = Release;
431435 };
GMStepperExample/GMStepperExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plistdeleted−8
@@ -1,8 +0,0 @@
1−<?xml version="1.0" encoding="UTF-8"?>
2−<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3−<plist version="1.0">
4−<dict>
5− <key>IDEDidComputeMac32BitWarning</key>
6− <true/>
7−</dict>
8−</plist>
GMStepperExample/GMStepperExample/AppDelegate.swift+1−1
@@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1414 var window: UIWindow?
1515
1616
17− func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
17+ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1818 // Override point for customization after application launch.
1919 return true
2020 }
GMStepperExample/GMStepperExample/Base.lproj/Main.storyboard+1−1
@@ -56,7 +56,7 @@
5656 <color key="value" red="0.90823972230000005" green="0.92638683320000004" blue="0.93171715740000005" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
5757 </userDefinedRuntimeAttribute>
5858 <userDefinedRuntimeAttribute type="number" keyPath="stepValue">
59− <real key="value" value="0.1"/>
59+ <real key="value" value="0.5"/>
6060 </userDefinedRuntimeAttribute>
6161 </userDefinedRuntimeAttributes>
6262 </view>