How to resize a UIImageView to fit the underlying image without moving it?(如何调整 UIImageView 的大小以适应底层图像而不移动它?)
问题描述
我有一个 UIImageView,它的框架在加载图像之前设置,对于图像来说总是太大,所以当我尝试圆角时,例如,没有任何反应.
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.
如何调整框架的大小,使其与底层图像的大小相同,同时确保 UIImageView 的中心点不会改变?
How can I resize the frame so it's the same size as the underlying image, while ensuring that the center point of the UIImageView does not change?
推荐答案
如果改变 UIView 的边界,中心不会改变.
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;
这篇关于如何调整 UIImageView 的大小以适应底层图像而不移动它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何调整 UIImageView 的大小以适应底层图像而不移动它?


- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 拆分 Drawable 2022-01-01