Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a partial compatibility layer with previous version #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions EFCountingLabel/Classes/EFCount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// THE SOFTWARE.

import Foundation
import QuartzCore

public protocol EFTiming {
func update(_ time: CGFloat) -> CGFloat
Expand Down
80 changes: 80 additions & 0 deletions EFCountingLabel/Classes/EFCountAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,46 @@ extension EFCountAdapter {

open class EFCountingButton: UIButton, EFCountAdapter {
public private(set) var counter = EFCounter()

open var formatBlock: ((CGFloat) -> String)? {
set {
if let formatBlock = newValue {
setUpdateBlock { value, button in button.setTitle(formatBlock(value), for: .normal) }
} else {
setUpdateBlock(nil)
}
}
@available(*, unavailable)
get {
return nil
}
}
open var attributedFormatBlock: ((CGFloat) -> NSAttributedString)? {
set {
if let attributedFormatBlock = newValue {
setUpdateBlock { value, button in button.setAttributedTitle(attributedFormatBlock(value), for: .normal) }
} else {
setUpdateBlock(nil)
}
}
@available(*, unavailable)
get {
return nil
}
}
open var completionBlock: (() -> Void)? {
set {
if let completionBlock = newValue {
setCompletionBlock { _ in completionBlock() }
} else {
setCompletionBlock(nil)
}
}
@available(*, unavailable)
get {
return nil
}
}

deinit {
counter.invalidate()
Expand All @@ -68,6 +108,46 @@ open class EFCountingButton: UIButton, EFCountAdapter {
open class EFCountingLabel: UILabel, EFCountAdapter {
public private(set) var counter = EFCounter()

open var formatBlock: ((CGFloat) -> String)? {
set {
if let formatBlock = newValue {
setUpdateBlock { value, label in label.text = formatBlock(value) }
} else {
setUpdateBlock(nil)
}
}
@available(*, unavailable)
get {
return nil
}
}
open var attributedFormatBlock: ((CGFloat) -> NSAttributedString)? {
set {
if let attributedFormatBlock = newValue {
setUpdateBlock { value, label in label.attributedText = attributedFormatBlock(value) }
} else {
setUpdateBlock(nil)
}
}
@available(*, unavailable)
get {
return nil
}
}
open var completionBlock: (() -> Void)? {
set {
if let completionBlock = newValue {
setCompletionBlock { _ in completionBlock() }
} else {
setCompletionBlock(nil)
}
}
@available(*, unavailable)
get {
return nil
}
}

deinit {
counter.invalidate()
}
Expand Down
2 changes: 1 addition & 1 deletion Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 18006cf8308f1ddc4db21317a6cf556416d587b1

COCOAPODS: 1.7.0.rc.1
COCOAPODS: 1.7.0
2 changes: 1 addition & 1 deletion Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.