中心4图像与约束的自动布局 [英] Center 4 images with constraints autolayout

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

问题描述

我是新来自动版式和我有点憋屈像它看起来的图像如何在各种不同的设备中心这4个图像。我试着申请自动配置的限制,但随后将有一个距离,不适合于所有设备。所以我的问题是我需要为了使具有相同距离中心所有的图像上的所有不同的图像应用哪些约束?

I'm new to autolayout and i'm kind of stuck on how to center these 4 images in all different devices like it looks on the images. i've tried to apply the auto configured constraints but then it will have that distance and that does not fit on all devices. So my question is what constraints do i need to apply on all different images in order to make all image centered with same distance?

下面是我在故事板细胞的样子:

Here is how my cell in storyBoard looks like:

的约束选项图像1图像:

image of the constraint options on image 1:

在模拟图像:

/// MY TRY ////

/// MY TRY ////

在这里,你可以看到,我已经添加了约束和结果?

Here you can see the constraints that i've added and the result?

结果:

推荐答案

您的做法是正确的差不多,它只是缺少大小约束的图像。

Your approach is almost correct, it simply lacks size constraints for the images.

如果要动态调整图像,并保持它们之间的空间常数,把图像约束的宽度为> = 20 (或任何其他值,取决于你的需要),并保持纵横比的约束。然后,从 UIImageView1 按Ctrl键为 UIImageView2 键,设置的宽度相等约束的。重复从 UIImageView1 UIImageView3 UIImageView1 UIImageView4

If you want to dynamically resize the images and keep the space between them constant, put constraints on the images for the width to be >=20(or any other value, depends on your needs) and a constraint for keeping the aspect ratio. Then ctrl-drag from UIImageView1 to UIImageView2 and set a constraint for equal widths. Repeat that from UIImageView1 to UIImageView3 and from UIImageView1 to UIImageView4.

如果你想他们之间的图像始终保持固定的大小和动态调整的空间则需要另一种方法:

If you want the images to always keep their fixed size and dynamically sized spaces between them you need another approach:

这里的窍门是把之间的UIImageViews 3个空UIViews,使它看起来像这样:

The trick here is to place 3 empty UIViews between the UIImageViews so that it looks like this:


  • 设置约束顶端所有视图

  • 设置约束到左和右为UIImageView1和4

  • 设置约束所有的UIImageViews为相同的宽度

  • 设置约束条件的UIImageViews之间的所有UIViews为相同的宽度

  • 设置约束所有视图之间的距离为0

  • 设置为UIViews宽度约束> = 0

  • Set constraints to the top for all views
  • Set constraints to the left and right for UIImageView1 and 4
  • Set constraints for all UIImageViews to the same width
  • Set constraints for all UIViews between the UIImageViews to the same width
  • Set constraints for all the distances between the views to 0
  • Set the width constraints for the UIViews to >= 0

这种方式使得之间的UIImageViews空UIViews动态调整和所有相同的宽度。

This way makes the empty UIViews between the UIImageViews to resize dynamically and all the same width.

我希望你的想法。

这篇关于中心4图像与约束的自动布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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