Skip to content

michalkonturek/ScreenBrightness

Repository files navigation

ScreenBrightness

Version Build Status Swift Platform License Twitter

ScreenBrightness allows you to monitor brightness of your device screen without a hassle.

Example

To run the example project, clone the repo, and run pod install from the Example directory first. Alternatively, you could run the demo by executing pod try ScreenBrightness in your terminal.

NB Screen brigthness of iOS simulators is always 0.5, so make sure you run it on a real device.

Demo

Usage

To start, simply import ScreenBrightness to your project

import ScreenBrightness

and initialize ScreenBrightness class, set its delegate

let screenBrightness = ScreenBrightness(screen: UIScreen.mainScreen())
screenBrightness.delegate = self

and then implement screenBrightnessDidChange method to start monitoring screen brightness changes.

func screenBrightnessDidChange() {
    print(screenBrightness.brightness)
    print(screenBrightness.isLight)
}

Properties

public weak var delegate: ScreenBrightnessMonitoring?

A delegate that conforms to ScreenBrightnessMonitoring protocol.

public var brightness: CGFloat

Returns screen brightness value.

public var isLight: Bool

Returns true if screen brightness is greater than defined threshold.

public var threshold: Float

Determines if brightness is ligt or dark. Default value is 0.5.

Installation

ScreenBrightness is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "ScreenBrightness"

License

ScreenBrightness is available under the MIT license. See the LICENSE file for more info.

Credits

Thsis repository is inspired by ASCScreenBrightnessDetector by André Schneider.

About

ScreenBrightness allows you to monitor brightness of your device screen without a hassle.

Resources

License

Stars

Watchers

Forks

Packages

No packages published