Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions CircularSlider/Classes/CircularSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ open class CircularSlider: UIView {
fileprivate var backingFractionDigits: NSInteger = 2
fileprivate let maxFractionDigits: NSInteger = 4
fileprivate var startAngle: CGFloat {
return -CGFloat(M_PI_2) + radiansOffset
return -.pi + radiansOffset
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
fileprivate var endAngle: CGFloat {
return 3 * CGFloat(M_PI_2) - radiansOffset
return 3 * .pi - radiansOffset
}
fileprivate var angleRange: CGFloat {
return endAngle - startAngle
Expand All @@ -72,7 +72,7 @@ open class CircularSlider: UIView {
return CGFloat(normalizedValue) * angleRange + startAngle
}
fileprivate var knobMidAngle: CGFloat {
return (2 * CGFloat(M_PI) + startAngle - endAngle) / 2 + endAngle
return (2 * .pi + startAngle - endAngle) / 2 + endAngle
}
fileprivate var knobRotationTransform: CATransform3D {
return CATransform3DMakeRotation(knobAngle, 0.0, 0.0, 1)
Expand Down Expand Up @@ -175,7 +175,7 @@ open class CircularSlider: UIView {
@IBInspectable
open var customDecimalSeparator: String? = nil {
didSet {
if let c = self.customDecimalSeparator, c.characters.count > 1 {
if let c = self.customDecimalSeparator, c.count > 1 {
self.customDecimalSeparator = nil
}
}
Expand All @@ -198,7 +198,7 @@ open class CircularSlider: UIView {
fileprivate func xibSetup() {
containerView = loadViewFromNib()
containerView.frame = bounds
containerView.autoresizingMask = [UIViewAutoresizing.flexibleWidth, UIViewAutoresizing.flexibleHeight]
containerView.autoresizingMask = [UIView.AutoresizingMask.flexibleWidth, UIView.AutoresizingMask.flexibleHeight]
addSubview(containerView)
}

Expand Down Expand Up @@ -289,9 +289,9 @@ open class CircularSlider: UIView {

fileprivate func configureFont() {
if #available(iOS 8.2, *) {
intFont = UIFont.systemFont(ofSize: 42, weight: UIFontWeightRegular)
decimalFont = UIFont.systemFont(ofSize: 42, weight: UIFontWeightThin)
divisaFont = UIFont.systemFont(ofSize: 26, weight: UIFontWeightThin)
intFont = UIFont.systemFont(ofSize: 42, weight: UIFont.Weight.regular)
decimalFont = UIFont.systemFont(ofSize: 42, weight: UIFont.Weight.thin)
divisaFont = UIFont.systemFont(ofSize: 26, weight: UIFont.Weight.thin)
}
}

Expand All @@ -305,14 +305,14 @@ open class CircularSlider: UIView {
backgroundCircleLayer.lineWidth = lineWidth
backgroundCircleLayer.fillColor = UIColor.clear.cgColor
backgroundCircleLayer.strokeColor = bgColor.cgColor
backgroundCircleLayer.lineCap = kCALineCapRound
backgroundCircleLayer.lineCap = CAShapeLayerLineCap.round
}

fileprivate func appearanceProgressLayer() {
progressCircleLayer.lineWidth = lineWidth
progressCircleLayer.fillColor = UIColor.clear.cgColor
progressCircleLayer.strokeColor = highlighted ? pgHighlightedColor.cgColor : pgNormalColor.cgColor
progressCircleLayer.lineCap = kCALineCapRound
progressCircleLayer.lineCap = CAShapeLayerLineCap.round
}

fileprivate func appearanceKnobLayer() {
Expand Down Expand Up @@ -348,8 +348,8 @@ open class CircularSlider: UIView {
strokeAnimation.fromValue = progressCircleLayer.strokeEnd
strokeAnimation.toValue = CGFloat(normalizedValue)
strokeAnimation.isRemovedOnCompletion = false
strokeAnimation.fillMode = kCAFillModeRemoved
strokeAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
strokeAnimation.fillMode = CAMediaTimingFillMode.removed
strokeAnimation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
progressCircleLayer.add(strokeAnimation, forKey: "strokeAnimation")
progressCircleLayer.strokeEnd = CGFloat(normalizedValue)
CATransaction.commit()
Expand Down Expand Up @@ -387,19 +387,19 @@ open class CircularSlider: UIView {
@objc fileprivate func handleRotationGesture(_ sender: AnyObject) {
guard let gesture = sender as? RotationGestureRecognizer else { return }

if gesture.state == UIGestureRecognizerState.began {
if gesture.state == UIGestureRecognizer.State.began {
cancelAnimation()
}

var rotationAngle = gesture.rotation
if rotationAngle > knobMidAngle {
rotationAngle -= 2 * CGFloat(M_PI)
} else if rotationAngle < (knobMidAngle - 2 * CGFloat(M_PI)) {
rotationAngle += 2 * CGFloat(M_PI)
rotationAngle -= 2 * .pi
} else if rotationAngle < (knobMidAngle - 2 * .pi) {
rotationAngle += 2 * .pi
}
rotationAngle = min(endAngle, max(startAngle, rotationAngle))

guard abs(Double(rotationAngle - knobAngle)) < M_PI_2 else { return }
guard abs(Double(rotationAngle - knobAngle)) < .pi else { return }

let valueForAngle = Float(rotationAngle - startAngle) / Float(angleRange) * valueRange + minimumValue
setValue(valueForAngle, animated: false)
Expand All @@ -422,8 +422,8 @@ open class CircularSlider: UIView {

fileprivate func addDoneButtonOnKeyboard() {
let doneToolbar: UIToolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: 320, height: 50))
let flexSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil)
let doneButton: UIBarButtonItem = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.done, target: self, action: #selector(resignFirstResponder))
let flexSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: nil, action: nil)
let doneButton: UIBarButtonItem = UIBarButtonItem(title: "Done", style: UIBarButtonItem.Style.done, target: self, action: #selector(resignFirstResponder))

doneToolbar.barStyle = UIBarStyle.default
doneToolbar.items = [flexSpace, doneButton]
Expand Down Expand Up @@ -451,7 +451,7 @@ extension CircularSlider: UITextFieldDelegate {

let newString = (textField.text! as NSString).replacingCharacters(in: range, with: string)

if newString.characters.count > 0 {
if newString.count > 0 {

let fmt = NumberFormatter()
let scanner: Scanner = Scanner(string:newString.replacingOccurrences(of: customDecimalSeparator ?? fmt.decimalSeparator, with: "."))
Expand All @@ -463,8 +463,8 @@ extension CircularSlider: UITextFieldDelegate {



for ch in newString.characters.reversed() {
if ch == fmt.decimalSeparator.characters.first {
for ch in newString.reversed() {
if ch == fmt.decimalSeparator.first {
decimalFound = true
break
}
Expand Down
18 changes: 14 additions & 4 deletions CircularSlider/Classes/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ extension String {

// add attributes
if #available(iOS 8.2, *) {
integer.addAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 42, weight: UIFontWeightRegular)], range: NSMakeRange(0, integer.length))
decimal.addAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 42, weight: UIFontWeightThin)], range: NSMakeRange(0, decimal.length))
integer.addAttributes(convertToNSAttributedStringKeyDictionary([convertFromNSAttributedStringKey(NSAttributedString.Key.font): UIFont.systemFont(ofSize: 42, weight: UIFont.Weight.regular)]), range: NSMakeRange(0, integer.length))
decimal.addAttributes(convertToNSAttributedStringKeyDictionary([convertFromNSAttributedStringKey(NSAttributedString.Key.font): UIFont.systemFont(ofSize: 42, weight: UIFont.Weight.thin)]), range: NSMakeRange(0, decimal.length))
} else {
integer.addAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 42)], range: NSMakeRange(0, integer.length))
decimal.addAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 42)], range: NSMakeRange(0, decimal.length))
integer.addAttributes(convertToNSAttributedStringKeyDictionary([convertFromNSAttributedStringKey(NSAttributedString.Key.font): UIFont.systemFont(ofSize: 42)]), range: NSMakeRange(0, integer.length))
decimal.addAttributes(convertToNSAttributedStringKeyDictionary([convertFromNSAttributedStringKey(NSAttributedString.Key.font): UIFont.systemFont(ofSize: 42)]), range: NSMakeRange(0, decimal.length))
}


Expand All @@ -77,3 +77,13 @@ extension String {
return attributeString
}
}

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertToNSAttributedStringKeyDictionary(_ input: [String: Any]) -> [NSAttributedString.Key: Any] {
return Dictionary(uniqueKeysWithValues: input.map { key, value in (NSAttributedString.Key(rawValue: key), value)})
}

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertFromNSAttributedStringKey(_ input: NSAttributedString.Key) -> String {
return input.rawValue
}
80 changes: 24 additions & 56 deletions Example/CircularSlider.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@
607FACCD1AFB9204008FA782 /* Frameworks */,
607FACCE1AFB9204008FA782 /* Resources */,
1C674ADCF218AA6B49DF035A /* [CP] Embed Pods Frameworks */,
8CF3058B29FCCBAB0A8A6E06 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -190,8 +189,6 @@
607FACE11AFB9204008FA782 /* Sources */,
607FACE21AFB9204008FA782 /* Frameworks */,
607FACE31AFB9204008FA782 /* Resources */,
3766C965FED481651042BB36 /* [CP] Embed Pods Frameworks */,
795E99317FA7641D03B83A84 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -215,11 +212,13 @@
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0800;
DevelopmentTeam = EFM8TST8DR;
LastSwiftMigration = 1020;
};
607FACE41AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0800;
DevelopmentTeam = EFM8TST8DR;
LastSwiftMigration = 1020;
TestTargetID = 607FACCF1AFB9204008FA782;
};
};
Expand All @@ -229,6 +228,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -270,73 +270,34 @@
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-CircularSlider_Example/Pods-CircularSlider_Example-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/CircularSlider/CircularSlider.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CircularSlider.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CircularSlider_Example/Pods-CircularSlider_Example-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
3766C965FED481651042BB36 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CircularSlider_Tests/Pods-CircularSlider_Tests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
795E99317FA7641D03B83A84 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CircularSlider_Tests/Pods-CircularSlider_Tests-resources.sh\"\n";
showEnvVarsInLog = 0;
};
8CF3058B29FCCBAB0A8A6E06 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CircularSlider_Example/Pods-CircularSlider_Example-resources.sh\"\n";
showEnvVarsInLog = 0;
};
A0DBC34D5C15591C6FC09432 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-CircularSlider_Tests-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
CB6D78A73B044BB97383D28D /* [CP] Check Pods Manifest.lock */ = {
Expand All @@ -345,13 +306,16 @@
files = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-CircularSlider_Example-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
Expand Down Expand Up @@ -491,13 +455,14 @@
baseConfigurationReference = 02859AB0A5542D4F901CFFD1 /* Pods-CircularSlider_Example.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = EFM8TST8DR;
INFOPLIST_FILE = CircularSlider/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = tigielle.CircularSliderExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -506,20 +471,22 @@
baseConfigurationReference = FF5DF7FC26706DE78FA649C3 /* Pods-CircularSlider_Example.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = EFM8TST8DR;
INFOPLIST_FILE = CircularSlider/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = tigielle.CircularSliderExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
607FACF31AFB9204008FA782 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = D9C581707A8406323C13847F /* Pods-CircularSlider_Tests.debug.xcconfig */;
buildSettings = {
DEVELOPMENT_TEAM = EFM8TST8DR;
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
Expand All @@ -532,14 +499,15 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
607FACF41AFB9204008FA782 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 601CAEE580F55D0ADD4E25C8 /* Pods-CircularSlider_Tests.release.xcconfig */;
buildSettings = {
DEVELOPMENT_TEAM = EFM8TST8DR;
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
Expand All @@ -548,7 +516,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?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>
2 changes: 1 addition & 1 deletion Example/CircularSlider/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return true
}
}
Expand Down
Loading