Text is truncated in ObjectView – Solution
Ran into an issue today, where the text in my FUIObjectView.subheadlineText was truncating, seemingly prematurely.
My cell configuration was as follows:
cell.headlineText = "St. Marys" cell.subheadlineText = "St. Marys PA\nUnited States"
Clearly, there is enough room for the text to be printed (the green background was added for debugging). What’s going on?
The issue is the newline character \n in the middle of the string. The Object View’s text engine will respect the newline character, but, since currently the subheadlineLabel.numberOfLines == 1, it will not print the second line of text, and is displaying the ellipsis … to indicate that there is truncated content to the end user. The A character is a casualty of the ellipsis display.
To get the display we want, we have a couple options:
- Increase the number of lines displayed for the subheadlineLabel. Here, the newline is fully respected.
cell.subheadlineLabel.numberOfLines = 2 // or 0 for unconstrained
- Insert a leading space before the \n character, after the A character. This provides a character where the ellipsis can be inserted, without stepping on the A.
cell.subheadlineText = "St. Marys PA \nUnited States"
- Reformat the string, substituting a comma for the newline.
cell.subheadlineText = "St. Marys PA\nUnited States".replacingOccurrences(of: "\n", with: ", ")
The latter option ended up being our desired solution.