我正在使用 autoLayout 并且对它很陌生,
我有一个如下所示的 UITableView Cell,UITableViewCell 高度是动态的,因此它的高度根据文本而变化。
我有两个标签 A 和 B,它们可以有可变长度的文本,但宽度是固定的,我的UITableViewCell 具有动态高度,那么我怎样才能将它们保持在中心右侧并与单元格的顶部和底部保持相等的距离,如上面两幅图所示。
To put the both labels in centre, you must put them in one view and then set that view in centre. so lets start and create a view say a labelContainer. as shown below
如图所示设置除了固定高度之外的约束,因此最终的约束将是固定超级视图的尾随空间、固定宽度并将垂直中心与超级视图对齐。
Now create two label as you want inside the labelContainer view as shown below picture.
Now your label will have constrains as labelA- fixed width, fixed top and trailing space to container view and fixed bottom space to label B. and for labelB- fixed width, fixed bottom and trailing space to container view and fixed top space to label A
现在您的所有约束将如下所示。
希望这会起作用。但不要忘记将标签设置为 sizeToFitContent 并将行数设置为 0
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)