Iphone - change the brightness of the screen, for example, iBook

In iBook, the user can adjust the brightness of the screen using the slider, right?

What should I do to implement this? What class or function should I use to control screen brightness?

thank

+3
source share
3 answers

As in iOS5, you can adjust the brightness of the display using the following:

[UIScreen mainScreen].brightness = 0.5;
+5
source

Hi, I find this open source on the Internet from alec jacobson

- (void) set_brightness:(float) new_brightness {
CGDirectDisplayID display[kMaxDisplays];
CGDisplayCount numDisplays;
CGDisplayErr err;
err = CGGetActiveDisplayList(kMaxDisplays, display, &numDisplays);

if (err != CGDisplayNoErr)
    printf("cannot get list of displays (error %d)\n",err);
for (CGDisplayCount i = 0; i < numDisplays; ++i) {
    CGDirectDisplayID dspy = display[i];
    CFDictionaryRef originalMode = CGDisplayCurrentMode(dspy);
    if (originalMode == NULL)
        continue;
            io_service_t service = CGDisplayIOServicePort(dspy);

    float brightness;
    err= IODisplayGetFloatParameter(service, kNilOptions, kDisplayBrightness,
                                    &brightness);
    if (err != kIOReturnSuccess) {
        fprintf(stderr,
                "failed to get brightness of display 0x%x (error %d)",
                (unsigned int)dspy, err);
        continue;
    }

    err = IODisplaySetFloatParameter(service, kNilOptions, kDisplayBrightness,
                                     new_brightness);
    if (err != kIOReturnSuccess) {
        fprintf(stderr,
                "Failed to set brightness of display 0x%x (error %d)",
                 (unsigned int)dspy, err);
        continue;
    }
}       

}
+1
source

API, , App Store, . .

, Apple.

+1

Source: https://habr.com/ru/post/1794405/


All Articles