Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yonat/BatteryView
Simple battery shaped UIView
https://github.com/yonat/BatteryView
battery swift
Last synced: about 1 month ago
JSON representation
Simple battery shaped UIView
- Host: GitHub
- URL: https://github.com/yonat/BatteryView
- Owner: yonat
- License: mit
- Created: 2016-11-28T14:55:39.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-11-01T13:55:53.000Z (2 months ago)
- Last Synced: 2024-12-01T14:47:29.935Z (about 1 month ago)
- Topics: battery, swift
- Language: Swift
- Size: 72.3 KB
- Stars: 52
- Watchers: 5
- Forks: 12
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-ios - BatteryView - Simple battery shaped UIView. (UI / Font)
- awesome-swift - BatteryView - Simple battery shaped UIView. (Libs / UI)
- awesome-swift - BatteryView - Simple battery shaped UIView. (Libs / UI)
- awesome-ios-star - BatteryView - Simple battery shaped UIView. (UI / Font)
- fucking-awesome-swift - BatteryView - Simple battery shaped UIView. (Libs / UI)
- awesome-swift - BatteryView - Simple battery shaped UIView ` 📝 a year ago ` (UI [🔝](#readme))
README
# BatteryView
Simple battery shaped UIView.[![Swift Version][swift-image]][swift-url]
[![Build Status][travis-image]][travis-url]
[![License][license-image]][license-url]
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/BatteryView.svg)](https://img.shields.io/cocoapods/v/BatteryView.svg)
[![Platform](https://img.shields.io/cocoapods/p/BatteryView.svg?style=flat)](http://cocoapods.org/pods/BatteryView)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
## Usage
```swift
let batteryView = BatteryView(frame: smallRect)
batteryView.level = 42 // anywhere in 0...100
batteryView.lowThreshold = 25 // battery fill becomes red if level is below this threshold
batteryView.gradientThreshold = 50 // battery fill gradually changes from green to red below this threshold
```## SwiftUI Usage
```swift
BatteryShape(level: $level)
```## Changing Appearance
The properties below can be set in Interface Builder, in code, or through a UIAppearance proxy (e.g., `BatteryView.appearance().borderColor = .gray`).
When using SwiftUI you can set them in the `BatteryShape` initializer .**Colors:**
```swift
batteryView.borderColor = .darkGray
batteryView.highLevelColor = .green
batteryView.lowLevelColor = .red
batteryView.noLevelColor = .gray
batteryView.noLevelText = "?" // shown over battery when the level is undefined or out of bounds
```**Battery Shape:**
```swift
batteryView.direction = .minXEdge // terminal facing leftbatteryView.terminalLengthRatio = 0.1 // relative to battery length
batteryView.terminalWidthRatio = 0.4 // relative to battery widthbatteryView.borderWidth = 2.5 // default is batteryLength / 20
batteryView.cornerRadius = 5 // default is batteryLength / 10
```## Installation
### CocoaPods:
```ruby
pod 'BatteryView'
```### Swift Package Manager:
```swift
dependencies: [
.package(url: "https://github.com/yonat/BatteryView", from: "1.4.4")
]
```## Meta
[@yonatsharon](https://twitter.com/yonatsharon)
[https://github.com/yonat/BatteryView](https://github.com/yonat/BatteryView)
[swift-image]:https://img.shields.io/badge/swift-4.2-orange.svg
[swift-url]: https://swift.org/
[license-image]: https://img.shields.io/badge/License-MIT-blue.svg
[license-url]: LICENSE.txt
[travis-image]: https://img.shields.io/travis/dbader/node-datadog-metrics/master.svg?style=flat-square
[travis-url]: https://travis-ci.org/dbader/node-datadog-metrics