/AnimateNumberText

Rolling animation of numbers in SwiftUI.

Primary LanguageSwiftMIT LicenseMIT

AnimateNumberText

SwiftUI-Version

Badge Badge Badge - Version Badge - Swift Package Manager Badge - Platform Badge - License


Support Double

Image

Support Int

Image

Support Minus

Image

Support NumberFormatter

Image

Support StringFormat

Image

Example

struct ContentView: View {
  @State var value: Double = 58.090
  @State var textColor: Color = .green
    
  var body: some View {
    Section("Double") {
      AnimateNumberText(font: .system(size: 55),
                        weight: .black,
                        value: $value,
                        textColor: $textColor)
      }
    }
    Button("Change Value") {
      value += 1
      textColor = Color.random
    }
  }
}

extension Color {
  static var random: Color {
    return Color(
      red: .random(in: 0...1),
      green: .random(in: 0...1),
      blue: .random(in: 0...1)
    )
  }
}

NumberFormatter Example

struct ContentView: View {
  @State var value: Double = 0
  
  var numberFormatter: NumberFormatter {
    let numberFormatter = NumberFormatter()
    numberFormatter.numberStyle = .currency
    numberFormatter.locale = .current
    numberFormatter.maximumFractionDigits = 1
    return numberFormatter
  }
  
  var body: some View {
    Section("NumberFormatter") {
      AnimateNumberText(value: $value,
                        textColor: $textColor,
                        numberFormatter: numberFormatter)
      }
    }
  }
}

StringFormat Example

struct ContentView: View {
  @State var value: Double = 0
  
  var body: some View {
    Section("StringFormatter") {
      AnimateNumberText(value: $value,
                        textColor: $textColor,
                        stringFormatter: "%@ ms")
      }
    }
  }
}

Installation

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 Alamofire as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/swift-man/AnimateNumberText.git", from: "0.5.0")
]