laser2302 laser2302 - 1 year ago 113
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

Answer Source

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.!!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download