jdog
jdog

Reputation: 10769

UIImageView scaling image

I have a UIImageView that holds one of several icons depending on the mode selected.

MODES: small truck, big truck, extended truck

The problem is the icons being passed are different sizes (i.e. big truck is longer than small truck).

The problem is I have set my UIImageView in storyboards to be the size of banana so as to make sure things don't bump up against it, but when the blueberry image loads it is scaled out because the UIImageView is not square because I had to make it a rectangle to fit a banana. Also, I want whatever icon is loaded to sit on the bottom of the UIImageView to be bottom aligned with the text next to it, but it appears that the UIImageView is loading its UIImage to the topleft corner.

I tried change the frame, but when the view loads the UIImageView jumps into position as if animated, but it is NOT animated.

self.myIconImageView.frame = CGRectMake(self.myIconImageView.frame.origin.x, self.myIconImageView.frame.origin.y, self.myIconImageView.image.size.width, self.myIconImageView.image.size.height);

It might be hard to tell, but the Pickup Truck image is being scaled (i.e. tires are not round).

enter image description here

enter image description here

Upvotes: 0

Views: 187

Answers (1)

vijeesh
vijeesh

Reputation: 1335

  self.myIconImageView.clipsToBounds = true
  self.myIconImageView.layer.masksToBounds = true

Try this

Upvotes: 0

Related Questions