Change UIImageView mode iPhone/iPad

2019-03-22 18:53发布

问题:

If I have an UIImageView with the mode set to center for example how can I change it to something else such as aspect fit with code?

回答1:

imageView.contentMode = UIViewContentModeScaleAspectFit;


回答2:

yourImageView.contentMode = UIViewContentModeScaleAspectFit;

you can set it to any of the following

UIViewContentModeScaleToFill,
UIViewContentModeScaleAspectFit,
UIViewContentModeScaleAspectFill,
UIViewContentModeRedraw,
UIViewContentModeCenter,
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight