Make the iPhone Screen Dim
Asked Answered
L

2

14

I have managed to ensure that the iPhone doesn't auto-lock using:

    [[ UIApplication sharedApplication ] setIdleTimerDisabled: YES ];

But how do I make the screen dim after a certain amount of time?

Thanks...

EDIT:

Think I've found a solution myself:

Use this method in your view controller to dim by adding a black view with 50% alpha. Make sure to set userInteractionEnabled = NO to pass events to underlying views.

- (IBAction)dim:(id)sender {
UIView *dimView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
dimView.backgroundColor = [UIColor blackColor];
dimView.alpha = 0.5f;
dimView.userInteractionEnabled = NO;
[self.view addSubview:dimView];
}

or, could risk it (but Apple may reject on submission):

[(id)[UIApplication sharedApplication] setBacklightLevel:1.0f];

That's a private API and shouldn't be used though...

Locomotive answered 22/11, 2011 at 22:45 Comment(2)
I'd recommend posting your edit as an answer for the sake of completeness.Araarab
I can't answer my own questions yet, think I have to build up points or somethingLocomotive
S
26

As of iOS 5 there is a public API in the UIScreen class. It has a brightness property that can be set. For those instances where you may want to go dimmer than the actual backlight allows, there is a wantsSoftwareDimming property that will automatically place a translucent layer that will give the appearance of being more dim than can be done in hardware. This is very similar to the method you came up with with the translucent UIView. It should be noted that using your solution or the software dimming API should not be used with many animations since you will pay a performance penalty with all the alpha blending.

See UIScreen Class Reference

Silence answered 22/11, 2011 at 22:59 Comment(1)
See @HashemAboonajmi's answer for iOS 7+.Obbard
C
3

in iOS 7 and later:

yourViewController.view.tintAdjustmentMode = UIViewTintAdjustmentModeDimmed;
Cycloparaffin answered 10/10, 2014 at 14:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.