Created
September 28, 2018 10:20
-
-
Save elpsk/af842c71dc013203d35fd9bcb2356286 to your computer and use it in GitHub Desktop.
Swift - Brightness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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