Skip to content

A SwiftUI library featuring a variety of battery visualisations.

License

Notifications You must be signed in to change notification settings

theMomax/BatteryView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

A SwiftUI library featuring a variety of battery visualisations.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages