自动布局拉伸图片问题 [英] auto layout stretching image issue

查看:117
本文介绍了自动布局拉伸图片问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从最左视图到市中心的拉伸图像。我试图钉扎约束使用左0,底部为0,和右侧300,但它并不完全后藤的中心。任何想法?

I'm trying to stretch an image from the very left of the view to the very center. I tried pinning constraints using left 0, bottom 0, and right 300, but it doesn't exactly goto the center. Any ideas?

推荐答案

假设你知道如何设置的左侧,顶部,底部,高度限制,我将解释如何设置正确的约束,这将导致的ImageView到跨度从左侧到屏幕中心。设置任何宽度约束将无法工作,因为宽度取决于为每个设备上的不同。

Assuming that you know how to set the left, top, bottom, height constraints I will explain you how to set the right constraint, which will cause the imageView to span from the left to the center of the screen. Setting any width constraint will not work, because the width depends is different on every device.


  • 点击您的ImageView

  • 选择对齐 - > 水平居中容器

  • 单击新创建的约束

  • 选择尺寸检查

  • 更改第一项中心X 追踪

  • click your imageView
  • choose Align -> Horizontally center in container
  • click on the newly created constraint
  • choose the Size Inspector
  • Change the First Item from Center X to Trailing

在容器标准水平居中使您的视图的中心X 其超级观点是对齐。如果你改变了第一项追踪而不是中心X 因此你调整你的视图的后缘/到您的上海华的的centerX。

The "standard" Horizontally center in container causes the Center X of your view and its super view to be aligned. If you change the First Item to Trailing instead of Center X you therefore align the trailing edge / right of your view to the centerX of your superview.

这篇关于自动布局拉伸图片问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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