Search code examples
iosobjective-cuiimageviewheightuislider

change UIImageView height with UISlider


I have 2 UIImageViews with a picture of a thermometer with no color and one with color. I want to set the height of the colored UIImageView dynamic with a UISlider.

So when the App starts I just want to show the thermometer without any color, when I slide my UISlider I want the colored UIImageView to increase the height. It should increase from 0 to full height(460).

How can I do that?

This is just an example of a more more complex situation.

I've tried with the following, but it just scales the whole picture, I just want to increase the height.

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

    [self.thermo_color setTransform:CGAffineTransformMakeScale(sender.value, sender.value)];

}

Check this link for an example photo: https://i.sstatic.net/PARUT.jpg

Thank You.


Solution

  • Te Controller structure:

    -MainView
    --UIImageView *themFull (full image with full color)
    --UIView *viewAnimated (a white view that you transform for the animation effect)
    --UIImageView *themEmpty (empty Image of thermometer)
    

    This Is the good way for do that:

    - (IBAction)my_slider:(UISlider *)sender {
    
        dispatch_async(dispatch_get_main_queue(), ^{
    
            [self.viewAnimated setFrame:CGRectMake(self.viewAnimated.frame.origin.x,
                                                    self.viewAnimated.frame.origin.y,
                                                    self.viewAnimated.frame.size.width,
                                                    self.viewAnimated.frame.size.width / sender.value)];
    
        });
    }
    

    the size of view have to be the same of the your UIImageViews