0

如何在单击按钮时更改屏幕的亮度?我正在使用此代码

[[UIScreen mainScreen] setBrightness:0.3f];

但它不再起作用了。我已将此代码放入按钮单击操作中。我需要对此做些什么特别的事情,或者我需要包含任何框架吗?

4

1 回答 1

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

可能对你有帮助,谢谢。

于 2013-10-03T13:30:28.540 回答