Reputation: 49730
I am working one Feature of setting Brightness of mainscreen i search lots of googling got one code.
UISlider *slider = (UISlider *)sender;
float fBrightness = slider.value;
[[UIScreen mainScreen]setBrightness:fBrightness];
But this code is worked Only iOS5 not in iOS4 when i am using this code in my apps i got warning and my app crash
warning: 'UIScreen' may not respond to '-setBrightness:'
so please anyone help me how to empliments this feature in iOS4 thank you
EDIT:-(Solution)
-(void)ActionBrightness{
NSUserDefaults *defaults2 = [NSUserDefaults standardUserDefaults]; //slidervalue from setting.bundle
float values = [defaults2 floatForKey:@"slider_preference"];
NSLog(@"value of slider %f",values);
//if(polygonView == nil){
polygonView = [[UIView alloc] initWithFrame: CGRectMake ( 0, 0, 500, 500)];
//add code to customize, e.g. polygonView.backgroundColor = [UIColor blackColor];
polygonView.userInteractionEnabled = NO;
if(values < 0.1){
polygonView.backgroundColor = [UIColor blackColor];//DARK_VIEW;
polygonView.alpha = 0.4;
}
else if((values < 0.2) && (values > 0.1)) {
polygonView.backgroundColor = [UIColor blackColor];//DARK_VIEW;
polygonView.alpha = 0.2;
}
else if((values < 0.3) && (values > 0.2)) {
polygonView.backgroundColor = [UIColor blackColor];//DARK_VIEW;
polygonView.alpha = 0.1;
}
else if((values < 0.4) && (values > 0.3)) {
polygonView.backgroundColor = [UIColor blackColor];//DARK_VIEW;
polygonView.alpha = 0.0;
}
else if((values < 0.5) && (values > 0.4)) {
polygonView.backgroundColor = [UIColor whiteColor];//DARK_VIEW;
polygonView.alpha = 0.1;
}
else if((values < 0.6) && (values > 0.5)) {
polygonView.backgroundColor = [UIColor whiteColor];//DARK_VIEW;
polygonView.alpha = 0.2;
}
NSLog(@"vakdfjkdf %f",values );
[self.view addSubview:polygonView];
[self.view bringSubviewToFront:polygonView];
[polygonView release];
}
Upvotes: 1
Views: 1074
Reputation: 6160
yeah you can do that by adding a blackView on your view and change its alpha based on the slider value .. it will looks like you are changing the brightness.
Upvotes: 1