简体   繁体   English

UILabel宽度似乎没有自动调整

[英]UILabel width doesn't seem to be automatically adjusting

I have two UILabel's, one for a temperature value and one for the degree's symbol. 我有两个UILabel,一个用于温度值,一个用于度数符号。 (It's because of the requirements of design that I have to have them as two separate labels instead of one). (由于设计的要求,我必须将它们作为两个单独的标签而不是一个)。

My expectation is that when the temperature increases or decreases the overall width of the label would increase/decrease. 我的期望是,当温度升高或降低时,标签的整体宽度将增加/减少。 I have a constraint that pins the degree symbol label to the right of the temperature so it seems to me that if the width of the temperature label increases/decreases then the degree symbol would move accordingly. 我有一个约束,将度数符号标签固定在温度的右侧,因此在我看来,如果温度标签的宽度增加/减少,度数符号将相应地移动。 Instead what it happening is the degree symbol position seems to remain static for some reason as you can see in the following two examples: 取而代之的是,度符号位置由于某些原因似乎保持静态,如以下两个示例所示:

在此处输入图片说明 在此处输入图片说明

Here are the constraints of the temperature label: 以下是温度标签的限制:

在此处输入图片说明

Here are the constraints of the degree symbol label: 以下是度数符号标签的约束:

在此处输入图片说明

Is there something I need to do to the temperature label to make its with auto expand/contract? 我需要对温度标签进行自动扩展/收缩处理吗?

EDIT: As requested, here is the temperature and degree symbol labels in relation to their containing view along with its constraints: 编辑:根据要求,以下是温度和温度符号标签及其包含的视图及其约束:

在此处输入图片说明 在此处输入图片说明

Your problem is that you're aligning the leading space of the degree label , to the trailing of Feels like label , so whatever the width of temperature label the degree will be steady at it's place , so remove that constraint and instead hook the leading of degree to trailing of 120 ( primary heart label aka temperature label ) 您的问题是,您正在将度数标签的前导空间与标签等Feels的尾部对齐,因此无论温度标签的宽度如何,度数都将在其位置处保持稳定,因此请删除该约束并钩住尾随度数为120( 主要心脏标签或温度标签)

在此处输入图片说明

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

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