Compare commits

..

No commits in common. "master" and "swift4" have entirely different histories.

7 changed files with 85 additions and 116 deletions

View File

@ -1 +1 @@
4.2
4.0

View File

@ -1,16 +1,14 @@
Pod::Spec.new do |s|
s.name = "GMStepper"
s.version = "2.2.1"
s.version = "2.1"
s.summary = "A stepper with a sliding label in the middle."
s.homepage = "https://github.com/gmertk/GMStepper"
s.screenshots = "https://raw.githubusercontent.com/gmertk/GMStepper/master/Screenshots/screenshot_1.gif"
s.license = 'MIT'
s.authors = { "Gunay Mert Karadogan" => "mertkaradogan@gmail.com",
"Brent Whitman" => "brent@pathym.com" }
s.author = { "Gunay Mert Karadogan" => "mertkaradogan@gmail.com" }
s.source = { :git => "https://github.com/gmertk/GMStepper.git", :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/gunaymertk'
s.platform = :ios, '8.0'
s.requires_arc = true
s.source_files = 'GMStepper/*.swift'
s.swift_version = '4.2'
end

View File

@ -15,27 +15,26 @@ import UIKit
didSet {
value = min(maximumValue, max(minimumValue, value))
handleIsLimitReached()
label.text = formattedValue
let isInteger = floor(value) == value
//
// If we have items, we will display them as steps
//
if isInteger && stepValue == 1.0 && items.count > 0 {
label.text = items[Int(value)]
}
else if showIntegerIfDoubleIsInteger && isInteger {
label.text = String(stringInterpolationSegment: Int(value))
} else {
label.text = String(stringInterpolationSegment: value)
}
if oldValue != value {
sendActions(for: .valueChanged)
}
}
}
private var formattedValue: String? {
let isInteger = Decimal(value).exponent >= 0
// If we have items, we will display them as steps
if isInteger && stepValue == 1.0 && items.count > 0 {
return items[Int(value)]
}
else {
return formatter.string(from: NSNumber(value: value))
}
}
/// Minimum value. Must be less than maximumValue. Defaults to 0.
@objc @IBInspectable public var minimumValue: Double = 0 {
@ -52,53 +51,37 @@ import UIKit
}
/// Step/Increment value as in UIStepper. Defaults to 1.
@objc @IBInspectable public var stepValue: Double = 1 {
didSet {
setupNumberFormatter()
}
}
@objc @IBInspectable public var stepValue: Double = 1
/// The same as UIStepper's autorepeat. If true, holding on the buttons or keeping the pan gesture alters the value repeatedly. Defaults to true.
@objc @IBInspectable public var autorepeat: Bool = true
/// If the value is integer, it is shown without floating point.
@objc @IBInspectable public var showIntegerIfDoubleIsInteger: Bool = true {
@objc @IBInspectable public var showIntegerIfDoubleIsInteger: Bool = true
/// Text on the left button. Be sure that it fits in the button. Defaults to "".
@objc @IBInspectable public var leftButtonText: String = "" {
didSet {
setupNumberFormatter()
leftButton.setTitle(leftButtonText, for: .normal)
}
}
/// Image on the left button. Defaults to nil.
@objc @IBInspectable public var leftButtonImage: UIImage? = nil {
/// Text on the right button. Be sure that it fits in the button. Defaults to "+".
@objc @IBInspectable public var rightButtonText: String = "+" {
didSet {
leftButton.setImage(leftButtonImage, for: .normal)
rightButton.setTitle(rightButtonText, for: .normal)
}
}
/// Image on the right button. Defaults to nil.
@objc @IBInspectable public var rightButtonImage: UIImage? = nil {
/// Text color of the buttons. Defaults to white.
@objc @IBInspectable public var buttonsTextColor: UIColor = UIColor.white {
didSet {
rightButton.setImage(rightButtonImage, for: .normal)
for button in [leftButton, rightButton] {
button.setTitleColor(buttonsTextColor, for: .normal)
}
}
}
/// Left button content insets. Defaults to ".zero".
@objc @IBInspectable public var leftButtonContentInsets: UIEdgeInsets = .zero {
didSet {
leftButton.contentEdgeInsets = leftButtonContentInsets
}
}
/// Right button content insets. Defaults to ".zero".
@objc @IBInspectable public var rightButtonContentInsets: UIEdgeInsets = .zero {
didSet {
rightButton.contentEdgeInsets = rightButtonContentInsets
}
}
/// Left button limit opacity. Defaults to "0.4".
@objc @IBInspectable public var leftButtonLimitOpacity: CGFloat = 0.4
/// Background color of the buttons. Defaults to dark blue.
@objc @IBInspectable public var buttonsBackgroundColor: UIColor = UIColor(red:0.21, green:0.5, blue:0.74, alpha:1) {
didSet {
@ -109,12 +92,15 @@ import UIKit
}
}
/// Label tap closure
@objc public var didTouchLabel: ((Double) -> Void)?
/// Block is called when the minimum is exceeded
@objc public var minimumExceeded: (() -> Void)?
/// Font of the buttons. Defaults to AvenirNext-Bold, 20.0 points in size.
@objc public var buttonsFont = UIFont(name: "AvenirNext-Bold", size: 20.0)! {
didSet {
for button in [leftButton, rightButton] {
button.titleLabel?.font = buttonsFont
}
}
}
/// Text color of the middle label. Defaults to white.
@objc @IBInspectable public var labelTextColor: UIColor = UIColor.white {
didSet {
@ -178,9 +164,6 @@ import UIKit
/// Color of the flashing animation on the buttons in case the value hit the limit.
@objc @IBInspectable public var limitHitAnimationColor: UIColor = UIColor(red:0.26, green:0.6, blue:0.87, alpha:1)
/// Formatter for displaying the current value
let formatter = NumberFormatter()
/**
Width of the sliding animation. When buttons clicked, the middle label does a slide animation towards to the clicked button. Defaults to 5.
*/
@ -194,8 +177,10 @@ import UIKit
lazy var leftButton: UIButton = {
let button = UIButton()
button.setImage(self.leftButtonImage, for: .normal)
button.setTitle(self.leftButtonText, for: .normal)
button.setTitleColor(self.buttonsTextColor, for: .normal)
button.backgroundColor = self.buttonsBackgroundColor
button.titleLabel?.font = self.buttonsFont
button.addTarget(self, action: #selector(GMStepper.leftButtonTouchDown), for: .touchDown)
button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchUpInside)
button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchUpOutside)
@ -205,8 +190,10 @@ import UIKit
lazy var rightButton: UIButton = {
let button = UIButton()
button.setImage(self.rightButtonImage, for: .normal)
button.setTitle(self.rightButtonText, for: .normal)
button.setTitleColor(self.buttonsTextColor, for: .normal)
button.backgroundColor = self.buttonsBackgroundColor
button.titleLabel?.font = self.buttonsFont
button.addTarget(self, action: #selector(GMStepper.rightButtonTouchDown), for: .touchDown)
button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchUpInside)
button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchUpOutside)
@ -217,7 +204,11 @@ import UIKit
lazy var label: UILabel = {
let label = UILabel()
label.textAlignment = .center
label.text = formattedValue
if self.showIntegerIfDoubleIsInteger && floor(self.value) == self.value {
label.text = String(stringInterpolationSegment: Int(self.value))
} else {
label.text = String(stringInterpolationSegment: self.value)
}
label.textColor = self.labelTextColor
label.backgroundColor = self.labelBackgroundColor
label.font = self.labelFont
@ -227,8 +218,6 @@ import UIKit
let panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(GMStepper.handlePan))
panRecognizer.maximumNumberOfTouches = 1
label.addGestureRecognizer(panRecognizer)
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(GMStepper.handleLabelTap))
label.addGestureRecognizer(tapRecognizer)
return label
}()
@ -258,7 +247,24 @@ import UIKit
@objc public var items : [String] = [] {
didSet {
label.text = formattedValue
let isInteger = floor(value) == value
//
// If we have items, we will display them as steps
//
if isInteger && stepValue == 1.0 && items.count > 0 {
var value = Int(self.value)
if value >= items.count {
value = items.count - 1
self.value = Double(value)
}
else {
label.text = items[value]
}
}
}
}
@ -295,28 +301,17 @@ import UIKit
setup()
}
fileprivate func setup() {
func setup() {
addSubview(leftButton)
addSubview(rightButton)
addSubview(label)
handleIsLimitReached()
backgroundColor = buttonsBackgroundColor
layer.cornerRadius = cornerRadius
clipsToBounds = true
labelOriginalCenter = label.center
setupNumberFormatter()
NotificationCenter.default.addObserver(self, selector: #selector(GMStepper.reset), name: UIApplication.willResignActiveNotification, object: nil)
}
func setupNumberFormatter() {
let decValue = Decimal(stepValue)
let digits = decValue.significantFractionalDecimalDigits
formatter.minimumIntegerDigits = 1
formatter.minimumFractionDigits = showIntegerIfDoubleIsInteger ? 0 : digits
formatter.maximumFractionDigits = digits
NotificationCenter.default.addObserver(self, selector: #selector(GMStepper.reset), name: NSNotification.Name.UIApplicationWillResignActive, object: nil)
}
public override func layoutSubviews() {
@ -337,9 +332,8 @@ import UIKit
value += stepValue
} else if stepperState == .ShouldDecrease {
value -= stepValue
}
}
}
deinit {
resetTimer()
@ -412,10 +406,6 @@ extension GMStepper {
}
}
@objc func handleLabelTap() {
didTouchLabel?(value)
}
@objc func reset() {
panState = .Stable
stepperState = .Stable
@ -442,11 +432,11 @@ extension GMStepper {
if value == minimumValue {
animateLimitHitIfNeeded()
minimumExceeded?()
} else {
stepperState = .ShouldDecrease
animateSlideLeft()
}
}
@objc func rightButtonTouchDown(button: UIButton) {
@ -526,19 +516,6 @@ extension GMStepper {
timerFireCount = 0
}
}
}
private extension GMStepper {
func handleIsLimitReached() {
let isLimitReached = value == minimumValue
leftButton.alpha = isLimitReached ? leftButtonLimitOpacity : 1
}
}
extension Decimal {
var significantFractionalDecimalDigits: Int {
return max(-exponent, 0)
}
}

View File

@ -168,14 +168,14 @@
TargetAttributes = {
3116C0D71DA4DD360015AC69 = {
CreatedOnToolsVersion = 8.0;
LastSwiftMigration = 1000;
LastSwiftMigration = 0900;
ProvisioningStyle = Automatic;
TestTargetID = 319C19311B4843EB005EFEE5;
};
319C19311B4843EB005EFEE5 = {
CreatedOnToolsVersion = 6.4;
DevelopmentTeam = 289M6XEDV4;
LastSwiftMigration = 1000;
LastSwiftMigration = 0900;
};
};
};
@ -282,7 +282,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.gmertk.GMStepperExampleTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 4.2;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GMStepperExample.app/GMStepperExample";
};
name = Debug;
@ -299,7 +300,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.gmertk.GMStepperExampleTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GMStepperExample.app/GMStepperExample";
};
name = Release;
@ -409,11 +411,11 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 289M6XEDV4;
INFOPLIST_FILE = GMStepperExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.gunaymert.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
@ -423,11 +425,11 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 289M6XEDV4;
INFOPLIST_FILE = GMStepperExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.gunaymert.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Release;
};

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

View File

@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

View File

@ -56,7 +56,7 @@
<color key="value" red="0.90823972230000005" green="0.92638683320000004" blue="0.93171715740000005" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="stepValue">
<real key="value" value="0.1"/>
<real key="value" value="0.5"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>