Setting UIImageView image affects layout constraints

谁说胖子不能爱 提交于 2019-12-05 09:30:21

Try to lower the content compression/hugging. I think (correct me if I am wrong) the UIImageView has by default a higher compression/hugging resistance than a UIView (251 to 250). You could try the code below:

    someImage.setContentHuggingPriority(UILayoutPriority(rawValue: 249), for: .horizontal)
    someImage.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 249), for: .horizontal)
    someImage.setContentHuggingPriority(UILayoutPriority(rawValue: 249), for: .vertical)
    someImage.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 249), for: .vertical)

Is your UIImageView masking to bounds? If the image is bigger than the UIImageView then by default it will extend past the bounds

imageView.layer.masksToBounds = true

Alternatively have you tried changing the content fit of the UIImageView to Aspect Fit for example?

try to set clipsToBounds property to true for UIImageView and check, since for few contentMode options the image goes out of bound of image view if the bounds are not enough to fill the content.

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