Predict the output
A name label and a date label sit in a row with default priorities. The name is very long. Which one truncates?
let name = UILabel() // "A very long display name..."
let date = UILabel() // "31 Oct"
// name.leading = container.leading
// date.leading = name.trailing + 8
// date.trailing = container.trailing
// both labels keep default hugging and compression prioritiesHint 1 of 1
Compare the two labels' priorities.
Choose an answer, then open Show answer below to check it.
Show answer
Answer: C Either one: the layout is ambiguous because the priorities are equal
Correct. Raise the date's compression resistance (say 751) so the name truncates.
Why not the others?
- A Always the name label. Only if you raise the date's compression resistance above the name's.
- B Always the date label. Nothing makes the date lower priority than the name.
- D Neither: the container grows. The container's edges are fixed in this layout.