自动布局的UILabel中的UITableViewCell [英] Autolayout UILabel in UITableViewCell

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

问题描述

我的autoLayout与合作,新的吧,

I am working with autoLayout and new to it,

我有一个UITableView细胞如下,的UITableViewCell高度是动态的,因此它已基于所述文本变化的高度。

I have a UITableView Cell as below, UITableViewCell height is dynamic, so it has varying height based on the text.

我有两个标签,A和B,它可以有可变长度的文本,但宽度是固定的,而我的的UITableViewCell有动力高度,所以我怎么可以让他们在中锋位置正确维护平等从细胞的顶部和底部的距离,如在上述的两个图像。

I have two labels A and B, which can have variable length text, but the width is fixed, and my UITableViewCell has dynamic height, so how can I keep them at center right and maintain equal distance from top and bottom of the cell, as seen in the above two images.

推荐答案

要放两个标签中的中心,必须装在一个视图,然后设置中心这一观点。所以让我们开始并创建一个视图说labelContainer。如下所示

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

设置约束,如图除了固定高度的画面,所以最后的约束会随着定势尾随空间超认为,固定宽度和对齐垂直中心超级视图。

Set the constrains as shown in picture except the Fixed height, so final constrains will be as fixe trailing space to super view, fixed width and align vertical centre to super view.

现在创建两个标签,只要你想如下图所示图片labelContainer视图中。

现在,您的标签将有约束的labelA-固定宽度,固定顶部和尾部空间容器视图和固定底部空间标记B.和labelB-固定宽度,固定底部和尾部空间容器视图和固定顶部空间要标记

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

现在所有的约束看起来就像是。

now your all constrains will look like as.

希望这会工作。 但是不要忘记设置行标签为sizeToFitContent和数量为0

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

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