简体   繁体   English

iOS-约束-UITableViewCell中彼此相邻的两个视图

[英]iOS - Constraints - Two Views next to each other in UITableViewCell

I have a problem with using constraints. 我在使用约束时遇到问题。 I want to put two UIViews next to each other in a UITableViewCell . 我想在UITableViewCell中将两个UIViews彼此相邻放置。 It should look like this: 它看起来应该像这样: 在此处输入图片说明

But after I add the suggested constraints, or when I add them manually, the cell always looks like this: 但是,在我添加建议的约束之后,或者当我手动添加它们时,单元格始终看起来像这样: 在此处输入图片说明

Why is it like that? 为什么会这样呢? The width of both UIViews should be flexible depending on the width of the screen. 根据屏幕的宽度,两个UIViews的宽度应灵活。

Can someone help me? 有人能帮我吗? Which constraints are missing? 缺少哪些约束?

Thanks! 谢谢!

I think the main thing you need is to add an "Equal Width" constraint between the two views. 我认为您需要的主要是在两个视图之间添加“等宽”约束。 If you are using Interface Builder, press CTRL and drag one view to the other, a menu will appear and select "Equal Widths". 如果使用的是Interface Builder,请按CTRL键并将一个视图拖到另一个视图,将出现一个菜单,然后选择“相等宽度”。

After that, you just need to pin your views borders to the Cell borders (except right border of left view to left border of right view) 之后,您只需要将视图边界固定到单元格边界(左视图的右边界到右视图的左边界除外)

Picture showing pin constraints 该图显示了引脚约束

http://i.stack.imgur.com/lhpVk.png http://i.stack.imgur.com/lhpVk.png

do not use suggested constraints, clear all constraints of both view. 不要使用建议的约束,请清除两个视图的所有约束。 Add constrains using "pin" 2nd option from left side(autolayout) for left side view add constraints 1) from left 2) from top 3) height 4) width 使用左侧左侧的第二个选项“ pin”添加约束(自动布局),以便在左侧视图中添加约束1)从左侧2)从顶部3)高度4)宽度

for right side view add constraints 1) from right 2) from top 3) height 4) width 对于右侧视图,添加约束1)从右侧2)从顶部3)高度4)宽度

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM