2013-10-03 108 views
0

如何在點擊按鈕時更改屏幕亮度?我正在使用此代碼如何降低屏幕的亮度?

[[UIScreen mainScreen] setBrightness:0.3f]; 

但它不再工作。我已將此代碼放入按鈕單擊操作中。我需要做什麼特殊的事情來處理這個或任何我需要包含的框架?

回答

0
在我的應用程序

我用這個:

//take slider in .h file 

    self.slider = [[UISlider alloc] initWithFrame:CGRectMake(give your frame)]; 

self.slider.minimumValue = 0;//here you have to set min value of slider as per you want 
self.slider.maximumValue = 1;//here you have to set max value of slider as per you want 
self.slider.continuous = YES; 

int myVal = self.slider.value; 
NSString *timeValue = [[NSString alloc] initWithFormat:@"%1d", myVal]; 

self.timeLabel.text = timeValue; 

// Attach an action to sliding 
    [self.slider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged]; 

- (void)sliderChanged:(UISlider *)sender 
{ 
    [self adjustImageBrightnessWithValue:sender.value]; 
} 

- (void)adjustImageBrightnessWithValue:(CGFloat)value 
{ 
    [[UIScreen mainScreen] setBrightness:value]; 
} 

可能它會幫助你,謝謝。

+0

Thanx dev。但我認爲你的方法沒有任何區別 - (void)adjustImageBrightnessWithValue :(CGFloat)的值 {[UIScreen mainScreen] setBrightness:value]; }和我提到的那一個。 [[UIScreen mainScreen] setBrightness:0.3f];是這樣嗎? – pankaj

+0

請檢查一下,因爲我給:http://www.datafilehost.com/d/ea81e71b –