laser2302 laser2302 - 10 months ago 49
Swift Question

Cropping or centering image in Swift

I have an image in an UIImageView. There are grey portions above and below the image because the image size doesn't have the same size as UIImageView. How can I crop or zoom the image in such a way that it just fits to cover the grey area above and below, or left and right?

enter image description here


you should set imageview's contentmode to UIViewContentMode.ScaleAspectFill and you should set propert clipsToBounds of imageview to true.

by this you will not get that gray space and image will fit in entire imageview.!!