0

I am changing UIScreen brightness using value of UISlider i tried this code

self.Slide = [[UISlider alloc] initWithFrame:CGRectMake(13, 0, 244, 23)];
[self.Slide addTarget:self action:@selector(sliderHandler:) forControlEvents:UIControlEventValueChanged];
self.Slide.minimumValue = 0.0f;
self.Slide.maximumValue = 1.0f;
[self.Slide setValue:0.0f];
self.Slide.value = [[UIScreen mainScreen] brightness];
[self.view addSubview:self.Slide];

and method called is

- (void)sliderHandler:(UISlider *)sender {
   [[UIScreen mainScreen] setBrightness:sender.value];
}

the method is call but brightness is not changing ......

and how can i set UISlider value to 0 initial ? thanks....

Denny
  • 285
  • 1
  • 2
  • 16
  • 1
    See http://stackoverflow.com/questions/10230796/is-iphone-simulators-brightness-adjustable - You can test it only on a device. – Martin R Aug 03 '13 at 12:00

1 Answers1

0

Please use this code and as for the slider value set maximum and minimum value as given in the code below UISlider Brightness

Whereas the below code would work too.

- (void)viewDidLoad
{
    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(0,0,300,40)];
    [slider addTarget:self action:@selector(sliderHandler:) forControlEvents:UIControlEventValueChanged];
    slider.minimumValue = 0.f;
    slider.maximumValue = 1.0f;
    slider.value = [[UIScreen mainScreen] brightness];
    [[self view]addSubview:slider];

    [super viewDidLoad];
}

- (void)sliderHandler:(UISlider *)sender
{
    //NSLog(@"value:%f", sender.value);
    [[UIScreen mainScreen] setBrightness:sender.value];
}

EDIT :

You could try this way too. Add a UIVIew of clear color to the view and increase the alpha component of this view upon the slider value changed event. By doing this , the view gets darkened and we get a feeling that the brightness of the app is reduced. This solution may not be very appropriate, but works just fine.

IronManGill
  • 7,222
  • 2
  • 31
  • 52