-
Notifications
You must be signed in to change notification settings - Fork 8
Description
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
.