ios - 在纵横比中设置图像高度在 Xcode 中填充自动布局

标签 ios swift autolayout uiimage constraints

如何在使用自动布局时设置纵横比填充图像。当我在 Storyboard 中设计时,它非常好,但是在设置图像时, ImageView 的高度非常高。我希望它是一个常量,我也为此添加了常量,但它不起作用。我正在使用最新的 Xcode。

最佳答案

来自 Apple Document,AspectFill 不保证剪辑内容。

The option to scale the content to fill the size of the view. Some portion of the content may be clipped to fill the view’s bounds.

enter image description here

所以你需要将clipToBounds属性设置为True,或者在Storyboard中设置。

enter image description here

关于ios - 在纵横比中设置图像高度在 Xcode 中填充自动布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37613780/

相关文章:

iphone - 自定义 UIPickerView 上方的 UIToolbar 未接收触摸

ios - 宽度和高度等于其 superView 以编程方式使用自动布局?

ios - Masonry如何使用autolayout UItableviewCell高度

ios - 嵌入固有大小的 View 会破坏动画

Swift 在回调中返回 Self

ios - 如何设置表格 View 单元格占据整个屏幕?

ios - ios:读取大文件时的内存使用情况

ios - 在 UITableViewController 中以编程方式切换 UITableView

swift - 我想在另一个 View Controller 上添加一个 View Controller 5 秒?

ios - 自定义字体错误