Skip to content

Instantly share code, notes, and snippets.

@elpsk
Created September 28, 2018 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elpsk/af842c71dc013203d35fd9bcb2356286 to your computer and use it in GitHub Desktop.
Save elpsk/af842c71dc013203d35fd9bcb2356286 to your computer and use it in GitHub Desktop.
Swift - Brightness
import UIKit
class BrightnessVC: UIViewController {
var timer: Timer?
override func viewDidLoad() {
super.viewDidLoad()
timer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { (t) in
self.brightness()
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
timer?.invalidate()
}
func brightness() {
let currentBrightness = UIScreen.main.brightness
print( "currentBrightness: \(currentBrightness)" )
self.view.backgroundColor = UIColor(red: 0, green: 1, blue: 0, alpha: currentBrightness)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment