Latest 1.3.4
Homepage https://github.com/yonat/BatteryView
License MIT
Platforms ios 8.0, requires ARC
Authors

Simple battery shaped UIView.

Swift Version
Build Status
License
CocoaPods Compatible
Platform
PRs Welcome

Usage

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

Changing Appearance

The properties below can be set in Interface Builder, in code, or through a UIAppearance proxy (e.g., BatteryView.appearance().borderColor = .gray).

Colors:

batteryView.borderColor    = .darkGray
batteryView.highLevelColor = .green
batteryView.lowLevelColor  = .red
batteryView.noLevelColor   = .gray

Battery Shape:

batteryView.direction = .minXEdge     // terminal facing left

batteryView.terminalLengthRatio = 0.1 // relative to battery length
batteryView.terminalWidthRatio = 0.4  // relative to battery width

batteryView.borderWidth = 2.5         // default is batteryLength / 20
batteryView.cornerRadius = 5          // default is batteryLength / 10

Installation

CocoaPods:

pod 'BatteryView'

Manually:

Copy Sources/* to your Xcode project.

Meta

@yonatsharon

https://github.com/yonat/BatteryView

Latest podspec

{
    "name": "BatteryView",
    "version": "1.3.4",
    "summary": "Simple battery shaped UIView.",
    "description": "Usage:nn```swiftnlet batteryView   = BatteryView(frame: smallRect)nbatteryView.level = 42 // anywhere in 0...100n```",
    "homepage": "https://github.com/yonat/BatteryView",
    "screenshots": "https://raw.githubusercontent.com/yonat/BatteryView/master/Screenshots/Battery.png",
    "license": {
        "type": "MIT",
        "file": "LICENSE.txt"
    },
    "authors": {
        "Yonat Sharon": "[email protected]"
    },
    "social_media_url": "http://twitter.com/yonatsharon",
    "swift_version": "4.2",
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source": {
        "git": "https://github.com/yonat/BatteryView.git",
        "tag": "1.3.4"
    },
    "source_files": "Sources/*"
}

Pin It on Pinterest

Share This