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.
You're looking for the brightness property of UIScreen.
Sample code:
[UIScreen mainScreen].brightness = 0.5;
Available in iOS 5.0 and later.
Related
I've successfully lowered the screen brightness of my app using this code
UIScreen.mainScreen().brightness = CGFloat(0.0)
However the auto brightness settings will increase the brightness over time. How could I make it stop adjusting to the brightness while inside my app?
As far as I know there is no way to disable auto brightness unless the user does it themselves in settings as Apple don't allow you to access general settings. You could have a function that lowers the brightness when something happens, which might work, depending on what app you're trying to make.
i do r&d but i didn't get anywhere how to increase or decrease brightness of mpmovieplayercontroller i have found in ALPlaycontroller it is a custom player but i don't want in this so please tell me there is any way to increase or decrease the brightness of mpmovieplayercontroller in IOS
You can't control the brightness of the movie player, it follows the device screen brightness.
You'll have to change the brightness of the movie either by editing it before serving it, or by building a custom player that uses CIFilter to adjust brightness of the frames as they arrive.
Why can't I set screen brightness in applicationDidEnterBackground or applicationWillResignActive?
This is my code:
-(void)applicationDidEnterBackground:(UIApplication *)application {
[[UIScreen mainScreen] setBrightness:1.0];
}
Can't understand it...!? It works in applicationDidEnterForeground etc, just not when i close the app using the home button.
Is there any other solution to this problem?
Update August 2016:
Brightness changes made by an app remain in effect until the device is locked, regardless of whether the app is closed. The system brightness (which the user can set in Settings or Control Center) is restored the next time the display is turned on.
https://developer.apple.com/reference/uikit/uiscreen/1617830-brightness
Original Post July 2012:
You're not allowed to set the brightness just before exiting. This is not documented anywhere but the following post on the dev forums is helpful:
https://devforums.apple.com/thread/139813?start=0&tstart=0
What should happen is the system-wide brightness is restored when the app is backgrounded. There is a known bug where this doesn't actually happen until the next time the backlight is switched off and on.
You can reproduce this easily by setting the brightness to 0 and pressing the home key. The home screen will still be very dark. Lock then unlock your device and the system brightness is restored.
Please file a bug about this! On the same post an Apple employee posted that repeated bug reports are helpful.
I never tried to set screen brightness at applicationDidEnterBackground.
I think you can change brightness of your application by using UIView with black background color on top of everything. Then set the alpha of this UIView. Then the result will looks exactly like real screen brightness.
I use this alternative because this method is only available for iOS5.
[[UIScreen mainScreen] setBrightness:1.0];
I want to support iOS3,4 also.
I have a camera taken picture, and I'd like to resize it to the exact size of a view. But... bounds.size on an iPhone 4 does not take account of the retina display.
I'd like a code that can give me the real pixel size of the view, so it can work on any device without having to test / to know the kind of hardware it runs on.
Do you know how I may do this ?
Every view has the contentScaleFactor property, which is typically 1.0 (3G, 3GS, iPad) or 2.0 (retina screens). Another approach is to use [[UIScreen mainScreen] scale], which has the same values.
note to remain compatible with iOS versions prior to 4.0, you have to check if the method is available using respondsToSelector:#selector(contentScaleFactor) before getting the value.
I'm putting in a UIDatePicker in a UIView and I can see that the UIDatePicker has a border that is some kind of a dark color on the bottom and it gets lighter as you get higher. I want the containing UIView to use the same colors so that the UIDatePicker flows with the rest of the view and doesn't stand out.
I can put in a gradient in the containing view, but I don't know what colors to use! If anyone could suggest them, I'd appreciate it.
mj
Light Color (Top): RGB: 145,146,154
Dark Color (Bottom): RGB: 30,31,44
Use Digital Color Meter that is built-in to OS X (in the Utilities folder).
The colours displayed in Xcode don't always match those when the app is viewed on an actual iOS device, especially for UIDatePicker object.
What I've found useful is the following:
Run the app on an iOS device with your objects on screen
Take a screenshot (hold down the home button and the power button together)
Email that screenshot to your Mac
Use the OS X Digital Color Meter on the screenshot to get accurate RGB values
Remember to check both retina and non retina devices for colour matching.