You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypographyTextField does not utilize paragraph styles to achieve its line height. This is because applying a paragraph style to UITextField can result in weird bugs (such as text wrapping to multiple lines) and also because text fields are by intention single line text views and so do not need paragraph styles. Because they are always single line, we can utilize intrinsicContentSize to achieve the correct lineHeight. (Multi-line text requires paragraph styles to achieve lineHeight.)
Single line labels and buttons (label.numberOfLines = 1) could be handled similarly. They might not need paragraph styles applied (or indeed any attributes at all, depending upon the typography) and line height could be achieved using intrinsicContentSize.
Pros
Using intrinsicContentSize to set height for single line text is more reliable and elegant, and probably less prone to odd rendering bugs. Completely avoiding attributed strings for simple typographies (no kerning, no text decorations) would be a win.
Cons
This would add some complexity because both labels and buttons can dynamically adjust numberOfLines and so a single component would need to be able to operate in both modes: using intrinsicContentSize to set height only when numberOfLines == 1 and relying on paragraph styles only when numberOfLines != 1.
The issue is even more complicated for buttons because the change happens on the titleLabel: UILabel? (which we do not subclass, replace, or override), and it would be more challenging to track changes made directly to button.titleLabel?.numberOfLines.
The text was updated successfully, but these errors were encountered:
mpospese
changed the title
**Proposal:** consider remove paragraph styles from single-line label and buttons
*Proposal:* consider remove paragraph styles from single-line label and buttons
Sep 16, 2022
TypographyTextField
does not utilize paragraph styles to achieve its line height. This is because applying a paragraph style to UITextField can result in weird bugs (such as text wrapping to multiple lines) and also because text fields are by intention single line text views and so do not need paragraph styles. Because they are always single line, we can utilizeintrinsicContentSize
to achieve the correctlineHeight
. (Multi-line text requires paragraph styles to achievelineHeight
.)Single line labels and buttons (
label.numberOfLines = 1
) could be handled similarly. They might not need paragraph styles applied (or indeed any attributes at all, depending upon the typography) and line height could be achieved usingintrinsicContentSize
.Pros
Using
intrinsicContentSize
to set height for single line text is more reliable and elegant, and probably less prone to odd rendering bugs. Completely avoiding attributed strings for simple typographies (no kerning, no text decorations) would be a win.Cons
This would add some complexity because both labels and buttons can dynamically adjust
numberOfLines
and so a single component would need to be able to operate in both modes: usingintrinsicContentSize
to set height only whennumberOfLines == 1
and relying on paragraph styles only whennumberOfLines != 1
.The issue is even more complicated for buttons because the change happens on the
titleLabel: UILabel?
(which we do not subclass, replace, or override), and it would be more challenging to track changes made directly tobutton.titleLabel?.numberOfLines
.The text was updated successfully, but these errors were encountered: