How to change image's size? Image does not fill

混江龙づ霸主 提交于 2019-12-13 07:26:03

问题


I'm trying to make the image rounded. It is already 128x128 (width and height) and the corner radius is 64. I want to zoom in before cutting the photo to take the full rounded size of the picture.

How to zoom it?

My code:

profileImage.layer.cornerRadius = 64
profileImage.clipsToBounds = true

I want to make it like this:


回答1:


You should set the UIImageView's content mode to .scaleAspectFill. That way, the image will fill up the whole container without distorting it.

profileImage.contentMode = .scaleAspectFill



回答2:


please first ensure your image height and width must be equal. and constraint set properly

after that change below to line

profileImage.layer.cornerRadius = profileImage.frame.size.width/2
profileImage.clipsToBounds = true


来源:https://stackoverflow.com/questions/45919697/how-to-change-images-size-image-does-not-fill

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!