ios - 在 XCode 中添加约束使 UIImageView 占据整个屏幕
问题描述
添加约束以水平对齐到中心后,如何防止 UIImageView 调整大小?每次我运行带有约束的程序时,最初大小为 300x300 的图像都会占据整个屏幕
解决方案
As soon as an image view comes under control of auto layout, its size is determined by its image — unless you take measures to prevent that. For example, you can add width and height constraints, or you can add external top-and-bottom and leading-and-trailing constraints that set the size relative to the superview or whatever.
(By the way, the very first thing you should always do is examine your interface in the View Debugger. If you really added only a constraint to align horizontally to the center, that is an error — an insufficient constraint — and the View Debugger will let you know of that fact.)
推荐阅读
- excel - VBA 将工作表另存为桌面的新工作簿(无论用户如何)
- php - 请求实体太大 Laravel
- mobx - 是否可以仅观察计算属性中访问的可观察对象的子集
- rust - 如何在不克隆数据的情况下循环调用正则表达式
- javascript - 检查数组的长度并推送或更新其中的对象
- spring-boot - Spring boot 2.4 Xmx On Layered Jar
- javascript - 在 R 中的 mapdeck/mapbox 中添加弹出窗口
- c - 我的列表有问题(奇怪的 Malloc 错误继续)
- reactjs - Webpack 开发服务器,但构建和复制文件
- python - 如何在命令行中增加变量的值?