Swiftpack.co - theMomax/BatteryView as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by theMomax.
theMomax/BatteryView v0.1.0
A SwiftUI library featuring a variety of battery visualisations.
⭐️ 14
🕓 2 years ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/theMomax/BatteryView.git", from: "v0.1.0")

license MIT swift 5.3 iOS 14 macOS 11 tvOS 13 watchOS 6 PRs welcome

BatteryView

A library featuring simple, animated battery icons written in SwiftUI.

Screen Shot 2021-08-24 at 18 05 58

Usage

A Battery can be initialized using Bindings to its core properties.

struct BatteryDemo: View {
    @State var level: Float = 1.0
    @State var state: BatteryState = .full
    @State var mode: BatteryMode = .normal
    
    var body: some View {
        Battery($level, $state, $mode)
            .frame(width: 30)
    }
}

You can set the BatteryStyle from the outside:

VStack {
    BatteryDemo()
        .batteryStyle(SFSymbolStyle(Monochrome())) // uses monochrome SFSymbolStyle
    BatteryDemo() // uses normal SFSymbolStyle
}.batteryStyle(SFSymbolStyle())

There is also a standalone SystemBattery for iOS, that shows the device's battery level, state, and mode:

SystemBattery()

Styles

There is only one style yet, but feel free to open a PR if you have implemented a new one!

SFSymbolStyle

This style mimics the "battery" SF Symbol at regular thickness, but can display any battery level. There is a colorful, monochrome, and black/white only configuration.

Multicolor (light mode) Monochrome (light mode) Monochrome (dark mode) Absolute (light mode)

GitHub

link
Stars: 14
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Related Packages

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics