1

I have a UIView of size width: 285 and height: 243. Within that view, I have a UIImageView (it is within that UIView according to Storyboard). That UIImageView has width 283 and height 241 (so that the UIView shows 1px around). I position that UIImageView 1px vertically and 1px horizontally from the UIView. Now, for some reason, everything shows fine within Storyboard, but once it runs, the UIImageView doesn't respect any of the height or width I gave. IF I set the mode to Scale to fill, it works, but I want Aspect fill which it doesn't work.

I am using auto-layout by the way. Any ideas?!

4

1 回答 1

1

你还没有说它“有效”是什么,所以我猜。

根据其定义,Aspect fit 可能会在 2 个边缘上显示不同的边框,因为它已经调整了图像的大小以供显示。如果您的目标是在图像周围设置边框,那么您应该:

  1. 删除容器视图(它没有任何好处)
  2. 为图像视图层添加边框
  3. 计算图像的纵横比
  4. 设置图像视图框架大小以适合图像

这篇文章中描述了许多选项:如何按比例缩放 UIImageView?.

于 2013-04-27T08:25:24.317 回答