2012-03-20 113 views
1

我正在设置一个功能设置亮度的屏幕 我搜索了大量的搜索代码。如何设置UISlider在iOS4中使用UISlider从Setting.bundle

UISlider *slider = (UISlider *)sender; 
float fBrightness = slider.value; 
[[UIScreen mainScreen]setBrightness:fBrightness]; 

但这段代码,当我使用此代码在我的应用我得到警告和我的应用程序崩溃

warning: 'UIScreen' may not respond to '-setBrightness:' 

所以请人帮助我如何empliments此功能的工作只有iOS5的不iOS4的在iOS4的 谢谢

编辑:-(解决方案)

-(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]; 


} 

回答

1

是的,你可以通过在你的视图中添加一个blackView并根据滑块值改变它的alpha值来实现这一点。它看起来像你在改变亮度。

+0

谢谢你,我会实现这一点,但有没有其他方式来实现这个东西或不.. ..? – 2012-03-20 08:45:57

+0

在iOS 4中这是简单的方法来做到这一点..我不认为有其他的方式来做到这一点。 – 2012-03-20 09:06:56