Giter VIP home page Giter VIP logo

efcountinglabel's Introduction

A label which can show number change animated in Swift, inspired by UICountingLabel.

中文介绍

Overview

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Version Needs
1.x Xcode 8.0+
Swift 3.0+
iOS 8.0+
4.x Xcode 9.0+
Swift 4.0+
iOS 8.0+
5.x Xcode 10.0+
Swift 5.0+
iOS 8.0+

Installation

CocoaPods

EFCountingLabel is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'EFCountingLabel'

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the Swift compiler.

Once you have your Swift package set up, adding EFCountingLabel as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/EFPrefix/EFCountingLabel.git", .upToNextMinor(from: "5.1.5"))
]

Setup

Simply initialize a EFCountingLabel the same way you set up a regular UILabel:

let myLabel = EFCountingLabel(frame: CGRect(x: 10, y: 10, width: 200, height: 40))
self.view.addSubview(myLabel)

You can also add it to your xib or storyboard , just make sure you set the class and module to EFCountingLabel.

Use

Set the format of your label. This will be filled with string (depending on how you format it) when it updates, you can provide a formatBlock, which permits greate control over how the text is formatted. If not provided, the default format will be "%d":

myLabel.setUpdateBlock { value, label in
    label.text = String(format: "%.2f%%", value)
}

Optionally, set the timing function. The default is EFTimingFunction.linear, which will not change speed until it reaches the end. Other options are described below in the Methods section.

myLabel.counter.timingFunction = EFTimingFunction.easeOut(easingRate: 3)

When you want the label to start counting, just call:

myLabel.countFrom(5, to: 100)

You can also specify the duration. The default is 2.0 seconds.

myLabel.countFrom(1, to: 10, withDuration: 3.0)

You can use common convinient methods for counting, such as:

myLabel.countFromCurrentValueTo(100)
myLabel.countFromZeroTo(100)

Behind the scenes, these convinient methods use one base method, which has the following full signature:

myLabel.countFrom(startValue: CGFloat, to: CGFloat, withDuration: TimeInterval)

You can get current value of your label using currentValue method (works correctly in the process of animation too):

let currentValue: CGFloat = myLabel.counter.currentValue

Optionally, you can specify a completionBlock to perform an acton when the label has finished counting:

myLabel.completionBlock = { () in
    print("finish")
}

Modes

There are currently four modes of counting.

  • EFTimingFunction.linear: Counts linearly from the start to the end;
  • EFTimingFunction.easeIn: Ease In starts out slow and speeds up counting as it gets to the end, stopping suddenly at the final value;
  • EFTimingFunction.easeOut: Ease Out starts out fast and slows down as it gets to the destination value;
  • EFTimingFunction.easeInOut: Ease In/Out starts out slow, speeds up towards the middle, and then slows down as it approaches the destination. It is a nice, smooth curve that looks great, and is the default method;
  • EFTimingFunction.easeInBounce;
  • EFTimingFunction.easeOutBounce.

Author

EyreFree, [email protected]

License

EFCountingLabel is available under the MIT license. See the LICENSE file for more info.

efcountinglabel's People

Contributors

coeur avatar eyrefree avatar hakefinance avatar iaugux avatar ikesyo avatar kirow avatar nikolaisa avatar rwinzhang avatar yoonhg84 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

efcountinglabel's Issues

Center text

How do I center the text in the view?
Thanks

iOS 15 beta compatibility

Issue Description

EFCountingLabel does not compile in Xcode 13 due to an ambiguous usage of pow in update of EFTimingFunction
Changing the method signature to func update(_ time: TimeInterval) -> TimeInterval solves the issue

currentValue() get error

Issue Description

Description

[Tell us about the issue]
image

当label滚动完毕之后 去通过 currentValue() 方法 获取当前值 得到的结果为 0

Leading zeros

Would be nice if it could automatically have leading zero's to keep a constant digit count.

Add custom format with decimals

Saw you posted on the other counting label library. I love how lightweight this is, do you have any intention of adding custom string formatting?

I would be looking to customize a string and still have that value increment say: "9.2'"

Compiler error "Ambiguous use of 'pow'" in xCode beta

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

  • I have read the README.md, but there is no information I need.
  • I have searched in existing issues, but did find a same one.

Issue Description

Xcode 13 Beta 1 compiler error: "Ambiguous use of 'pow'" in public enum EFTimingFunction: EFTiming {

Description

[Tell us about the issue]

Reproduce

compile EFCountingLabel
[The steps to reproduce this issue. What are the parameters, where did you put your code, etc.]
compile EFCountingLabel

Other Comment

[Add anything else here]

Animated count always starts from 0

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

  • I have read the README.md, but there is no information I need.
  • I have searched in existing issues, but did find a same one.

Issue Description

Description

Whenever I count from current value the numbers always starts from 0

Reproduce

Call
self.progressLabel.countFromCurrentValueTo(CGFloat(progress.progress))

Other Comment

[Add anything else here]

UIButtonLabel view inaccessible

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

  • I have read the README.md, but there is no information I need.
  • I have searched in existing issues, but did find a same one.

Issue Description

Description

I need access to view with text, but it hidden with

override open var titleLabel: UILabel? {
    get {
        return countingLabel
    }
}

underlying method

EFCountingButtonLabel.setTextValue(_ value: CGFloat) {
    button.setTitle(..., for: .normal)
}

writes to UIButtonLabel, not to EFCountingLabel

Simple solution will be just to remove titleLabel override from EFCountingButton. It does nothing anyway.

More complex idea - is to rewrite component and make counter as separate logical model. i.e. extract counting logic from EFCountingLabel to EFCounting. use EFCounting in EFCountingButton and EFCountingLabel similar to EFCountingButtonLabel in current implementation.

It could be that I will make pull request on weekends...

README says the default duration is 2 seconds, but it's 0 seconds (no animation)

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

  • I have read the README.md, but there is no information I need.
  • I have searched in existing issues, but did find a same one.

Issue Description

README says the default duration is 2 seconds, but it's 0 seconds (no animation)

Description

README says:

You can also specify the duration. The default is 2.0 seconds.

Code says:

countFrom(startValue, to: endValue, withDuration: 0)

countFromCurrentValueTo(endValue, withDuration: 0)

countFromZeroTo(endValue, withDuration: 0)

Reproduce

Documentation issue

Other Comment

Deployment target warning

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

  • [ x] I have read the README.md, but there is no information I need.
  • [x ] I have searched in existing issues, but did find a same one.

Issue Description

Description

Hello! There is a warning about deployment target version in Xcode 13.2.1 and EFCountingLabel 5.1.4 installed via SPM.
Снимок экрана 2022-01-12 в 00 37 31

Reproduce

Get Xcode 13.2.1 and install EFCountingLabel 5.1.4 via SPM.

Other Comment

Show currency

Thanks a lot for this awesome library — one question though:

If I want to count from 82€ to 95€ within a function, how can I achieve this? expenseValueLabel.countFrom(82, to: 95, withDuration: 1) works nicely, but I can't figure how to show the € sign in the label.

Thanks in advance for your help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.