简体   繁体   中英

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 . 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.

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".

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

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

for right side view add constraints 1) from right 2) from top 3) height 4) width

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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