From eaeae253a4e80ff0beeb353387f10044cd435143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20C=C5=93ur?= Date: Wed, 6 Mar 2019 18:33:31 +0800 Subject: [PATCH] Fix spelling in enum: Liner -> linear --- ACLabelCounting/ViewController.swift | 14 ++++----- README.md | 38 ++++++++++++------------ Source/ACLabelCounting.swift | 44 +++++++++++++--------------- 3 files changed, 47 insertions(+), 49 deletions(-) diff --git a/ACLabelCounting/ViewController.swift b/ACLabelCounting/ViewController.swift index e4063c8..0cb80cb 100644 --- a/ACLabelCounting/ViewController.swift +++ b/ACLabelCounting/ViewController.swift @@ -21,8 +21,8 @@ class ViewController: UIViewController { // label.count(from: 0, // to: 100, // duration: 5, -// animationType: .EaseIn, -// dataType: .Double) { txt in +// animationType: .easeIn, +// dataType: .double) { txt in // return "\(txt) %" // } @@ -30,11 +30,11 @@ class ViewController: UIViewController { label.count(from: 0, to: 100, duration: 5, - animationType: .EaseIn, - dataType: .Int) { text -> NSAttributedString in - let appandString = " / 100" - let string = "\(text)\(appandString)" - let range = (string as NSString).range(of: appandString) + animationType: .easeIn, + dataType: .int) { text -> NSAttributedString in + let appendString = " / 100" + let string = "\(text)\(appendString)" + let range = (string as NSString).range(of: appendString) let attributedString = NSMutableAttributedString(string: string) attributedString.addAttribute(NSAttributedString.Key.foregroundColor, diff --git a/README.md b/README.md index 2e7b762..b02410d 100644 --- a/README.md +++ b/README.md @@ -20,37 +20,37 @@ pod 'ACLabelCounting' ``` swift label.count(to: 100) ``` -从 10 到 100 的计数动画,持续时间是 5 秒钟,动画类型是渐入效果,数据类型是 .Double 类型。 +从 10 到 100 的计数动画,持续时间是 5 秒钟,动画类型是渐入效果,数据类型是 .double 类型。 ``` swift label.count(from: 10, to: 100, duration: 5, - animationType: .EaseIn, - dataType: .Double) + animationType: .easeIn, + dataType: .double) ``` -从 0 到 100 的计数动画,持续时间是 5 秒钟,动画类型是渐出效果,数据类型是 .Int 类型。字符串格式化是在字符串后面增加一个 `%`。 +从 0 到 100 的计数动画,持续时间是 5 秒钟,动画类型是渐出效果,数据类型是 .int 类型。字符串格式化是在字符串后面增加一个 `%`。 ``` swift label.count(from: 0, to: 100, duration: 5, - animationType: .EaseOut, - dataType: .Int) { txt in + animationType: .easeOut, + dataType: .int) { txt in return "\(txt) %" } ``` -从 0 到 100 的计数动画,持续时间是 5 秒钟,动画类型是渐 入效果,数据类型是 .Int 类型。字符串格式化就是在字符串有面加上 `/ 100` ,它颜色是亮灰色的。 +从 0 到 100 的计数动画,持续时间是 5 秒钟,动画类型是渐 入效果,数据类型是 .int 类型。字符串格式化就是在字符串有面加上 `/ 100` ,它颜色是亮灰色的。 ``` swift label.count(from: 0, to: 100, duration: 5, - animationType: .EaseIn, - dataType: .Int) { text -> NSAttributedString in - let appandString = " / 100" - let string = "\(text)\(appandString)" - let range = (string as NSString).range(of: appandString) + animationType: .easeIn, + dataType: .int) { text -> NSAttributedString in + let appendString = " / 100" + let string = "\(text)\(appendString)" + let range = (string as NSString).range(of: appendString) let attributedString = NSMutableAttributedString(string: string) attributedString.addAttribute(NSForegroundColorAttributeName, @@ -66,19 +66,19 @@ label.count(from: 0, ``` swift enum ACLabelCountingDataType { - case Int - case Double + case int + case double } ``` 数据类型是 Int 或者 Double。 ``` swift enum ACLabelCountingAnimationType { - case None - case Liner - case EaseIn - case EaseOut - case EaseInOut + case none + case linear + case easeIn + case easeOut + case easeInOut } ``` 计数动画效果的类型分别是:没有效果(和线性效果一样)、线性效果、渐入效果、渐出效果、渐入渐出效果。他们分别对应的函数是: diff --git a/Source/ACLabelCounting.swift b/Source/ACLabelCounting.swift index 053c57b..969e57c 100644 --- a/Source/ACLabelCounting.swift +++ b/Source/ACLabelCounting.swift @@ -14,23 +14,23 @@ struct LabelCountingConst { } enum ACLabelCountingAnimationType { - case None - case Liner - case EaseIn - case EaseOut - case EaseInOut + case none + case linear + case easeIn + case easeOut + case easeInOut } enum ACLabelCountingDataType { - case Int - case Double + case int + case double } class ACLabelCounting: UILabel { private var progress: Double = 0 - private var dataType: ACLabelCountingDataType = .Int - private var animationType: ACLabelCountingAnimationType = .None + private var dataType: ACLabelCountingDataType = .int + private var animationType: ACLabelCountingAnimationType = .none private var duration: TimeInterval = LabelCountingConst.defaultDuration private var displayLink: CADisplayLink! = CADisplayLink() private var lastUpdate: TimeInterval = Date.timeIntervalSinceReferenceDate @@ -92,25 +92,23 @@ class ACLabelCounting: UILabel { private func handleText(with: Double, type: ACLabelCountingDataType) -> String { switch type { - case .Int: + case .int: return String(format: "%.0lf", with) - default: + case .double: return String(format: "%.2lf", with) } } private func renderScale(type: ACLabelCountingAnimationType) -> Double { switch type { - case .None: - return liner(progress: progress, totle: Double(duration)) - case .EaseIn: + case .none, .linear: + return linear(progress: progress, totle: Double(duration)) + case .easeIn: return easeIn(progress: progress, totle: Double(duration)) - case .EaseOut: + case .easeOut: return easeOut(progress: progress, totle: Double(duration)) - case .EaseInOut: + case .easeInOut: return easeInOut(progress: progress, totle: Double(duration)) - default: - return liner(progress: progress, totle: Double(duration)) } } @@ -158,8 +156,8 @@ class ACLabelCounting: UILabel { func count(from fromValue: Double = 0.0, to toValue: Double, duration time: TimeInterval = LabelCountingConst.defaultDuration, - animationType: ACLabelCountingAnimationType = .None, - dataType: ACLabelCountingDataType = .Int, + animationType: ACLabelCountingAnimationType = .none, + dataType: ACLabelCountingDataType = .int, formatTextClosure: @escaping (String) -> String = { text -> String in return text }) { assert((fromValue >= 0 && toValue >= 0), "the fromValue or toValue must be not negative!") @@ -178,8 +176,8 @@ class ACLabelCounting: UILabel { func count(from fromValue: Double = 0.0, to toValue: Double, duration time: TimeInterval = LabelCountingConst.defaultDuration, - animationType: ACLabelCountingAnimationType = .None, - dataType: ACLabelCountingDataType = .Int, + animationType: ACLabelCountingAnimationType = .none, + dataType: ACLabelCountingDataType = .int, attributedTextClosure: @escaping (String) -> NSAttributedString) { self.attributedTextClosure = attributedTextClosure @@ -192,7 +190,7 @@ class ACLabelCounting: UILabel { } extension ACLabelCounting { - func liner(progress: Double, totle: Double) -> Double { + func linear(progress: Double, totle: Double) -> Double { return progress / totle }