将UIImageView与约束一起使用 [英] Using UIImageView together with constraints

查看:286
本文介绍了将UIImageView与约束一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIImageView在我的应用程序中保存一个个人资料图片。方面是Aspect Fit。但我有一些问题。



我已经将一个禁忌从UIImageView固定到上面的更大的UImageView,并带有superView的前导空间。



>



但在运行时看起来像这样:





在IB中看起来像这样:



>



我应该怎么做才能在这里实现正确的行为?



谢谢!
Erik

解决方案

您的图片视图正根据您设置显示的图片调整自己的大小。



此行为在(例如)文本视图中非常有用,您希望视图增长以显示所有文本。



一个解决方案是为视图添加约束,以保持您设置的大小:从右键拖动视图,然后像添加任何其他约束一样添加宽度约束,然后添加垂直高度约束宽高比约束。



另一种解决方案是提供正确大小的资源,以便视图自动调整为正确的尺寸。


I've a UIImageView that holds a profile image in my app. The aspect is "Aspect Fit". But I have some problems.

I've pinned a contraint from the UIImageView to the larger UImageView above and with the leading space to superView.

but it looks like this on runtime:

Way too big and placed wrongly.

It also looks like this in IB:

What should I be doing to achieve the right behaviour here?

Thanks! Erik

解决方案

You image view is resizing itself based on the image you set it to display.

This behaviour very useful in (e.g.) text views where you want a view to grow to display all the text. It's sometimes less useful in image views which are part of a static UI.

One solution it to add constraints to the view to keep the size you set: right drag from the view to itself and then add a width constraint just as you would any other contstraint then either add a vertical height constraint or an aspect ratio constraint.

Another solution is to provide correctly sized assets so the view autosizes to the correct dimensions.

这篇关于将UIImageView与约束一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆