Skip to content

Commit

Permalink
Merge branch 'master' of github.com:suzuki-0000/CountdownLabel
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-0000 committed Sep 18, 2018
2 parents 07358b6 + b11f974 commit dc5bc01
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 16 deletions.
14 changes: 13 additions & 1 deletion CountdownLabel.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0830;
LastUpgradeCheck = 0920;
ORGANIZATIONNAME = suzuki_keishi;
TargetAttributes = {
892106CF1C3CF4140007CDEC = {
Expand Down Expand Up @@ -329,14 +329,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -379,14 +385,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0830"
LastUpgradeVersion = "0920"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -40,6 +40,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
Expand All @@ -59,6 +60,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0830"
LastUpgradeVersion = "0920"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -10,6 +10,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables>
Expand All @@ -31,6 +32,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
29 changes: 27 additions & 2 deletions CountdownLabel/CountdownLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,12 @@ extension CountdownLabel {

func updateText() {
guard diffDate != nil else { return }


let date = diffDate.addingTimeInterval(round(timeCounted * -1)) as Date
// if time is before start
let formattedText = timeCounted < 0
? dateFormatter.string(from: date1970.addingTimeInterval(0) as Date)
: dateFormatter.string(from: diffDate.addingTimeInterval(round(timeCounted * -1)) as Date)
: self.surplusTime(date)

if let countdownAttributedText = countdownAttributedText {
let attrTextInRange = NSAttributedString(string: formattedText, attributes: countdownAttributedText.attributes)
Expand All @@ -292,6 +293,30 @@ extension CountdownLabel {
setNeedsDisplay()
}

//fix one day bug
func surplusTime(_ to1970Date: Date) -> String {
let calendar = Calendar.init(identifier: .gregorian);
var labelText = timeFormat;
let comp = calendar.dateComponents([.day, .hour, .minute, .second], from: date1970 as Date, to: to1970Date)

if let day = comp.day ,let _ = timeFormat.range(of: "dd"){
labelText = labelText.replacingOccurrences(of: "dd", with: String.init(format: "%02ld", day))
}
if let hour = comp.hour ,let _ = timeFormat.range(of: "hh"){
labelText = labelText.replacingOccurrences(of: "hh", with: String.init(format: "%02ld", hour))
}
if let hour = comp.hour ,let _ = timeFormat.range(of: "HH"){
labelText = labelText.replacingOccurrences(of: "HH", with: String.init(format: "%02ld", hour))
}
if let minute = comp.minute ,let _ = timeFormat.range(of: "mm"){
labelText = labelText.replacingOccurrences(of: "mm", with: String.init(format: "%02ld", minute))
}
if let second = comp.second ,let _ = timeFormat.range(of: "ss"){
labelText = labelText.replacingOccurrences(of: "ss", with: String.init(format: "%02ld", second))
}
return labelText
}

func updatePauseStatusIfNeeded() {
guard paused else {
return
Expand Down
8 changes: 4 additions & 4 deletions CountdownLabel/LTMorphingLabel/LTMorphingLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ extension LTMorphingLabel {
}
totalFrames = Int(ceil(morphingDuration / frameRate))

let totalDelay = Float((text!).characters.count) * morphingCharacterDelay
let totalDelay = Float((text!).count) * morphingCharacterDelay
totalDelayFrames = Int(ceil(totalDelay / frameRate))
}

Expand Down Expand Up @@ -263,7 +263,7 @@ extension LTMorphingLabel {

let topOffset = (bounds.size.height - charHeight) / 2.0

for char in textToDraw.characters {
for char in textToDraw {
let charSize = String(char).size(withAttributes: [.font: font])
charRects.append(
CGRect(
Expand Down Expand Up @@ -399,7 +399,7 @@ extension LTMorphingLabel {
var limbo = [LTCharacterLimbo]()

// Iterate original characters
for (i, character) in previousText.characters.enumerated() {
for (i, character) in previousText.enumerated() {
var progress: Float = 0.0

if let closure = progressClosures[
Expand All @@ -415,7 +415,7 @@ extension LTMorphingLabel {
}

// Add new characters
for (i, character) in (text!).characters.enumerated() {
for (i, character) in (text!).enumerated() {
if i >= diffResults?.0.count {
break
}
Expand Down
12 changes: 6 additions & 6 deletions CountdownLabel/LTMorphingLabel/LTStringDiffResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ public extension String {

guard let anotherString = anotherString else {
let diffResults: [LTCharacterDiffResult] =
Array(repeating: .delete, count: characters.count)
let skipDrawingResults: [Bool] = Array(repeating: false, count: characters.count)
Array(repeating: .delete, count: self.count)
let skipDrawingResults: [Bool] = Array(repeating: false, count: self.count)
return (diffResults, skipDrawingResults)
}

let newChars = anotherString.characters.enumerated()
let lhsLength = characters.count
let rhsLength = anotherString.characters.count
let newChars = anotherString.enumerated()
let lhsLength = self.count
let rhsLength = anotherString.count
var skipIndexes = [Int]()
let leftChars = Array(characters)
let leftChars = Array(self)

let maxLength = max(lhsLength, rhsLength)
var diffResults: [LTCharacterDiffResult] = Array(repeating: .add, count: maxLength)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0830;
LastUpgradeCheck = 0920;
ORGANIZATIONNAME = suzuki_keishi;
TargetAttributes = {
89993D911C3FAD910099AC14 = {
Expand Down Expand Up @@ -285,14 +285,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -332,14 +338,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -369,6 +381,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = CountdownLabelExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -382,6 +395,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = CountdownLabelExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand Down

0 comments on commit dc5bc01

Please sign in to comment.