Gobinath Ed
Gobinath Ed

Reputation: 229

Why I'm unable to decrease the brightness using a UISlider?

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?

Upvotes: 1

Views: 161

Answers (2)

Yogesh Suthar
Yogesh Suthar

Reputation: 30488

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

_displayImage.alpha = sender.value;

Upvotes: 1

Ravi
Ravi

Reputation: 2451

just use the following answer

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

    _displayImage.alpha=sender.value;

}

Upvotes: 1

Related Questions