Git Product home page Git Product logo

numbermorphview's Introduction

NumberMorphView

Build Status Version License Platform

NumberMorphView a view like label for displaying numbers which animate with transition using a technique called number tweening or number morphing.

alt text

Usage

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

Interface builder

  1. Drag a UIView into your view controller.
  2. Change the class to NumberMorphView in the identity inspector.
  3. Change intrinsic size from default to placeholder in the size inspector.
  4. Create an IBOutlet in your view controller.

Set the digit of number view as shown below:

numberView.currentDigit = 5;

Animate to nextDigit as shown below.

numberView.nextDigit = 8;

From code

NumberMorphView can be used with or without auto layout. Usage of intrinsic content size is recommended. Preferred aspect ratio of the view is 13 : 24.

let numberView = NumberMorphView();
numberView.fontSize = 64;
numberView.currentDigit = 5;
let preferedSize = numberView.intrinsicContentSize();
numberView.frame = CGRect(x: 10, y: 10, width: preferedSize.width, height: preferedSize.height);
self.view.addSubview(numberView);

dispatch_after(5, dispatch_get_main_queue()) {
    numberView.nextDigit = 7;
}

Note: Intrinsic content size is changed after setting fontSize.

Customizing animations

  • To set the animation duration:
numberView.animationDuration = 4;
  • To change the type of animation, set the interpolator.
numberView.interpolator = NumberMorphView.SpringInterpolator();

Already available interpolators are LinearInterpolator, OvershootInterpolator, SpringInterpolator, BounceInterpolator, AnticipateOvershootInterpolator, and CubicHermiteInterpolator. Also you can add new interpolators. The interpolator class needs to conform to InterpolatorProtocol as shown below:

class MyLinearInterpolator: InterpolatorProtocol {
    func getInterpolation(x: CGFloat) -> CGFloat {
        return x;
    }
}

Requirements

  • iOS 8.0+
  • Swift 2.2

Installation

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

use_frameworks!
pod 'NumberMorphView', '0.2.0'

Author

Abhinav Chauhan

License

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

numbermorphview's People

Contributors

albinekcom avatar maxim-pervushin avatar me-abhinav avatar ozgur 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

numbermorphview's Issues

swift 5 support

i am using NumberMorphView in my swift 5 and xcode 12.2 project but after giving class name to view , view object is not recognizing view.currentDigit...... please help me as soon as possible

Pod not getting from Swift 3 code

Hi There,

Apparently even after the latest PR to include support for swift 3, the podspec still grabbing the code from the 0.1.1 tag, which has not been updated with this new code.

So using Cocoapods still get the code for Swift 2.2.

I think you need to get a new tag in place and update the spec, or just make the spec point to master, since Dev is not in sync with it as well.

Thanks!

Swift 4 support?

Hi, thanks for this great library!

Are there any plans to add Swift 4 support?

Swift3

Any plan for a Swift3 migration ?

Tried with Xcode8 --> Convert syntax to Swift 3 and works like magic.
It will be a matter of uploading new code.

Ticker Animation?

Thank you for building this!!

Would be really awesome to see some sort of ticker animation? Like what Robinhood has. I could see that being used by a lot of people :)

Index out of range

Hi, I couldn't use this library, I get index out of range in

func updateAnimationFrame()
Sometimes at pNext and sometimes at pCur

let pCur = endpoints_scaled[_currentDigit];
let pNext = endpoints_scaled[_nextDigit];

I am using Swift 4 with Xcode 9.2

Implement sizeThatFits

The Readme says: "Preferred aspect ratio of the view is 13 : 24"

Instead of handing over the task of making sure the aspect ratio is always (which most people will probably fail), it would be much easier to implement the siteThatFits: method and return a correct size for the view.

It would be awesome if you could implement this! I would do it myself, it should just be a few lines, but I'm too busy :S (bad excuse).

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.