How to resize a UIImageView to fit the underlying image without moving it?

后端 未结 2 1479
没有蜡笔的小新
没有蜡笔的小新 2021-02-15 15:09

I have a UIImageView whose frame, set before the image is loaded, is always too large for the image, so when I try to round the corners, for example, nothing happens.

Ho

2条回答
  •  旧时难觅i
    2021-02-15 16:12

    If you change the bounds of a UIView the center will not change.

    CGRect bounds;
    
    bounds.origin = CGPointZero;
    bounds.size = newImage.size;
    
    imageView.bounds = bounds;
    imageView.image = newImage;
    

提交回复
热议问题