Search code examples
iosobjective-cxcodecgrectmake

UIImageView won't change size


I am trying to alter the width and height of an UIImageView object but for some reason I can't.

This is the code I used:

-(void)setMenuImages
{ 
        self.menuImageButton.image=[UIImage imageNamed:@"myimage.jpg"]; 
        self.menuImageButton.frame=CGRectMake(0,0,20,150); 
}

What am I doing wrong? The (UIImageView) menuImageButton is not created programmatically, but from storyboard interface with initial leading, trailing, width and height constraints.


Solution

  • You can self. menuImageButton.translatesAutoresizingMaskIntoConstraints = false in viewDidLoad and remove their constraints or you can add those constraints as IBOutlets and change them like

    self.imageWidthConstraint.constant = 20;
    self.imageHeightConstraint.constant = 150;
    

    UPDATE

    To declare constraints in your header file you need to select those constrains and right click drag to the .h file as show in the gif

    enter image description here