support iOS 13 dark mode

This commit is contained in:
Yonat Sharon 2019-09-15 21:36:07 +03:00
parent 538d5cc959
commit d4c9aeb84a
2 changed files with 25 additions and 2 deletions

View File

@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
- support iOS 13 dark mode.
## [1.3.9] - 2019-09-12 ## [1.3.9] - 2019-09-12
### Fixed ### Fixed

View File

@ -49,7 +49,7 @@ extension Int {
/// label shown over battery when the level is undefined or out of range /// label shown over battery when the level is undefined or out of range
@IBInspectable open dynamic var noLevelText: String? = "?" @IBInspectable open dynamic var noLevelText: String? = "?"
@IBInspectable open dynamic var borderColor: UIColor = .black { @IBInspectable open dynamic var borderColor: UIColor = .foreground {
didSet { didSet {
bodyOutline.borderColor = borderColor.cgColor bodyOutline.borderColor = borderColor.cgColor
terminalOutline.borderColor = borderColor.cgColor terminalOutline.borderColor = borderColor.cgColor
@ -181,7 +181,7 @@ extension Int {
case .fullBattery: case .fullBattery:
terminalOpening.backgroundColor = currentFillColor.cgColor terminalOpening.backgroundColor = currentFillColor.cgColor
case 0 ..< .fullBattery: case 0 ..< .fullBattery:
terminalOpening.backgroundColor = (backgroundColor ?? .white).cgColor terminalOpening.backgroundColor = (backgroundColor ?? .background).cgColor
default: default:
terminalOpening.backgroundColor = noLevelColor.cgColor terminalOpening.backgroundColor = noLevelColor.cgColor
} }
@ -214,3 +214,21 @@ extension CALayer {
return CGPoint(x: frame.midX, y: frame.midY) return CGPoint(x: frame.midX, y: frame.midY)
} }
} }
extension UIColor {
static var background: UIColor {
if #available(iOS 13, *) {
return .systemBackground
} else {
return .white
}
}
static var foreground: UIColor {
if #available(iOS 13, *) {
return .label
} else {
return .black
}
}
}