本文介绍了如何在iOS4中使用UISlider从Setting.bundle设置UIScreen亮度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在设置一个设置主屏幕亮度的功能
i搜索大量googling得到一个代码。
I am working one Feature of setting Brightness of mainscreeni search lots of googling got one code.
UISlider *slider = (UISlider *)sender;
float fBrightness = slider.value;
[[UIScreen mainScreen]setBrightness:fBrightness];
但是当我在我的应用程序中使用此代码时,此代码仅适用于iOS5而不是iOS4警告和我的应用程序崩溃
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:'
所以请任何人帮我如何在iOS4中恭维这个功能
谢谢
so please anyone help me how to empliments this feature in iOS4 thank you
-(解决方案)
-(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];
}
推荐答案
是的,你可以通过在视图上添加blackView并根据滑块值更改其alpha来实现这一点..看起来你正在改变亮度。
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.
这篇关于如何在iOS4中使用UISlider从Setting.bundle设置UIScreen亮度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!