UIView的动态高度多的UILabel [英] UIView with dynamic height multiple UILabel

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

问题描述

我在里面制作自定义的UIView与2的UILabel,具有动力高度各的UILabel。
我无法设置为动态的高度限制。 (我是新来的自动布局和放大器; iOS的东西)。

两者UILabels被连接到彼此从顶部和放大器;底部,水平对齐到上海华。当我改变的UILabel的一个内容,UIView的和的UILabel不按要求调整。

请建议。附加截图电流限制。


解决方案

我按照您的要求为您制作一个演示。从下面的链接下载它,<​​/ P>

自动调整的UIView和的UILabel

循序渐进指南: -

第1步: - 设置约束到的UIView

1)龙头2)前3名)尾随(从MAINVIEW)

在这里输入的形象描述

第2步: - 设置约束到标签1

1)龙头2)前3名)尾随(从它的SuperView)

在这里输入的形象描述

第3步: - 设置约束到标签2

1)龙头2)前3名)尾随(从它的SuperView)

在这里输入的形象描述

第4步: - 最靠谱从UIView的给钮来的UILabel

在这里输入的形象描述

第5步: - (可选)设置限制为UIButton的

1)龙头2)底部3)尾随4)固定高度(从MAINVIEW)

在这里输入的形象描述

输出: -

在这里输入的形象描述

注意: - 请确认您已= 0 Label属性设置的行数

在这里输入的形象描述

我希望这个信息足以根据UILabel的高度,自动调整的UILabel根据文本理解自动调整的UIView。

I'm making a custom UIView with 2 UILabel in it, with each UILabel having dynamic height. I'm unable to set constraints for dynamic height. (I'm new to Auto-Layout & iOS stuff).

Both UILabels are connected to each other from Top & Bottom, and are Horizontally aligned to superview. And when I change content of one of the UILabel, UIView and UILabel does not resize as required.

Please suggest. Attaching screenshots for current constraints.

解决方案

I made a demo for you according to your requirement. Download it from below link,

Autoresize UIView and UILabel

Step by Step Guide :-

Step 1 :- Set constrain to UIView

1) Leading 2) Top 3) Trailing (From mainview)

Step 2 :- Set constrain to Label 1

1) Leading 2) Top 3) Trailing (From it's superview)

Step 3 :- Set constrain to Label 2

1) Leading 2) Top 3) Trailing (From it's superview)

Step 4 :- Most tricky give botton to UILabel from UIView .

Step 5 :- (Optional) Set constrain to UIButton

1) Leading 2) Bottom 3) Trailing 4) Fixed Height (From mainview)

Output :-

Note :- Make sure you have set Number of lines =0 in Label property.

I hope this info enough to understand Autoresize UIView according to UILabel's height and Autoresize UILabel According to text.

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

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