A library featuring simple, animated battery icons written in SwiftUI.
A Battery
can be initialized using Binding
s 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()
There is only one style yet, but feel free to open a PR if you have implemented a new one!
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) |
---|---|---|---|