Search code examples
iphoneiosxcodeipadxcode4

Letting user adjust brightness in application


I am making a clock app and I wanted to know how can I check what the current brightness level is set to and how can i adjust brightness in my application in xcode 4 with a UISlider instead of telling the user to go to their iphone/ipad setting app and adjust the brightness there? I can't find any code/api for it.

I have seen quite a few clock apps in appstore where the user can adjust the brightness of the display just by moving the finger up or down.


Solution

  • You're looking for the brightness property of UIScreen.

    Sample code:

    [UIScreen mainScreen].brightness = 0.5;
    

    Available in iOS 5.0 and later.