1
votes

In my app, I'm using UISlider to reduce/improve the brightness of a UIImage. My slider's min value=0 and max value=1.Slider's current value is 1; When I move the slider from 1 to 0.7 my UIImage is getting bright but when I move from that 0.7 to 1, UIImage isn't reducing the brightness; Here is the code for my UISlider's Action:

-(IBAction)sliderBright:(UISlider*)sender
{
    float alphavalue;
    value2 = sender.value;
    if (value1>=value2) {//I fixed value1=1.0 in Viewdidload();
        NSLog(@"The value of the slider and Alpha is %f,", value2);
        alphavalue= value2;
        value2=value1;
    }
    else{
        alphavalue= value2+0.2;
        value2=value1;
    }
    _displayImage.alpha=alphavalue;

}

How can I fix it?Alpha value for a UIImage control the whiteness, similarly is there any way to control the blackness of UIImage?

2
change value2=value1; to value1=value2;Kawa

2 Answers

1
votes

just use the following answer

   -(IBAction)sliderBright:(UISlider*)sender
{

    _displayImage.alpha=sender.value;

}
1
votes

Just set UISlider's value to UIImage's alpha in your method.

_displayImage.alpha = sender.value;