Silver challenge question

I thought I had this one working back when I first did the chapter, but going back now it appears my solution wasn’t working as well as I thought. If I have a long enough name to be close to filling 2 lines, it starts out looking correct:


but if I rotate the device to horizontal & then back to vertical, it no longer wraps the name correctly, instead it wants to shove the value label off the right side of the screen:

I have a constraint between the trailing edge of the value label and the trailing margin, but it seems to selectively ignore that. I don’t even get an error message in the log about conflicting constraints.

The only thing I’ve been able to do to fix this is to set a preferred width for the name label, but since that’s a fixed value it doesn’t update when you rotate the device or run on a different size screen, so that isn’t really a good solution.

Did you try tinkering :slight_smile: with the constraint’s priority?

You were on the right track. The problem turned out not to be the priority on the value label constraint, it was the priorities on the Name label. I forgot to lower its vertical content hugging and horizontal content compression resistance priorities. When I did that, the problem went away.

When I update layout, layout have error.
I change nameLabel trailing size.
It works fine.

error

I saw that same trailing edge constraint error. In theory, you could add a constraint to prevent the serial number label from overlapping the value label; in practice, the serial number isn’t ever going to be big enough for that to be an issue.

I saw the same error and ignored it for the same reason