UILabel width doesn't seem to be automatically adjusting
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:


The few constraint you've shown look good. But there has to be more. In "theory" you probably want to (a) pin the right anchor of the degree symbol while (b) allowing the left side of the temperature symbol to expand. So far you've posted neither of those constraints. At that point I might assume that you might be confusing the layout engine by using the centerXanchor. (Everything you've posted with top/centerY are superfluous as everything is fine vertically.)
– dfd
Sep 13 '18 at 17:31
1 Answer
1
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 )

Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Can you upload the whole screenshot of the temperature screen....Then it will be better to understand constraints
– Keshav Raj
Sep 13 '18 at 17:29