简体   繁体   中英

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

在此处输入图片说明

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