GithubHelp home page GithubHelp logo

xingql / ascscreenbrightnessdetector Goto Github PK

View Code? Open in Web Editor NEW

This project forked from schneiderandre/ascscreenbrightnessdetector

0.0 2.0 0.0 703 KB

Detects screen brightness changes and provides some useful delegate methods.

License: MIT License

ascscreenbrightnessdetector's Introduction

ASCScreenBrightnessDetector

Build Status Version Platform

ASCScreenBrightnessDetector lets you easily detect screen brightness changes and provides some useful delegate methods.

For Example it's very easy to switch between a day and night theme optimized for different lighting conditions:

ASCScreenBrightnessDetector Demo

Usage

This repository contains an example project that uses the methods provided by ASCScreenBrightnessDetector - just build and run to see it in action.

Please note: The screen brightness detection will only work on a real device, the Xcode Simulators screen brightness is always 0.5.

Wherever you want to use ASCScreenBrightnessDetector, import the header file as follows:

#import "ASCScreenBrightnessDetector.h"

or when using CocoaPods:

#import <ASCScreenBrightnessDetector/ASCScreenBrightnessDetector.h>

To detect the current screen brightness or style you can easily use:

ASCScreenBrightnessDetector *brightnessDetector = [ASCScreenBrightnessDetector new];

NSLog(@"Screen brightness: %f", brightnessDetector.screenBrightness);

ASCScreenBrightnessStyle style = brightnessDetector.screenBrightnessStyle;
switch (style) {
    case ASCScreenBrightnessStyleDark:
        // Do something, e.g. set a dark theme.
        break;
    case ASCScreenBrightnessStyleLight:
        // Do something else, e.g set a light theme.
        break;
}

To continuously detect screen brightness changes implement ASCScreenBrightnessDetector as an instance variable, set the delegate and use the following delegate methods:

- (void)screenBrightnessDidChange:(CGFloat)brightness
{
    NSLog(@"The new brightness is: %f", brightness);
}

- (void)screenBrightnessStyleDidChange:(ASCScreenBrightnessStyle)style
{
    NSLog(@"The new style is: %u", style);
}

Properties

The object that acts as the delegate.

id<ASCScreenBrightnessDetectorDelegate> delegate;

The brightness level of the screen between 0.0 and 1.0, inclusive. (read-only)

CGFloat screenBrightness;

The style indicates if the screen brightness is dark or light and depends on the defined threshold. (read-only)

ASCScreenBrightnessStyle screenBrightnessStyle;

The threshold determines whether the brightness style is light or dark. It must have a value between 0.0 and 1.0, inclusive. The default value is 0.5.

 CGFloat threshold;

Delegate Methods

Tells the delegate when the screens brightness changed and returns a float value between 0.0 and 1.0, inclusive.

- (void)screenBrightnessDidChange:(CGFloat)brightness;

Tells the delegate when the screens brightness style changed and returns an ASCScreenBrightnessStyle enumeration.

- (void)screenBrightnessStyleDidChange:(ASCScreenBrightnessStyle)style;

Installation

From CocoaPods

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

pod "ASCScreenBrightnessDetector"

Manually

Drag the ASCScreenBrightnessDetector.h and ASCScreenBrightnessDetector.m source files to your project and you are done.

Author

André Schneider, @aschndr

License

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

ascscreenbrightnessdetector's People

Watchers

James Cloos avatar Mass avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.