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
{{ message }}
Repository navigation
Commit 9fee22b
Browse filesBrowse the repository at this point in the historyBrowse files
Center a single-line iOS TextInput's text within its lineHeight
A single-line `TextInput` whose `lineHeight` is larger than its font
draws its value, its placeholder and typed text at the bottom of the
line instead of in the middle. `lineHeight` reaches the field as the
paragraph style's minimum and maximum line height, and TextKit puts all
of the extra leading above the glyphs, so a 16 pt font in a 24 pt line
is drawn 4 pt low. CSS splits the leading equally above and below the
glyphs (https://www.w3.org/TR/CSS2/visudet.html#leading).
Layout already makes a single-line field as tall as its line, and
`UITextField` centers the font's own line in its text rect. A
single-line field therefore draws without the line height: it is
removed from the default text attributes, which also style the
placeholder and typed text, and from the attributed text the field is
given. Multi-line fields keep the line height, which spaces their
lines.
Layout measures the field from the attributed string in the state, so
that string keeps its line heights. A private attribute records the
line height removed from each range of the field's text, and the text
written back to the state gets each range's own value again. Text typed
into an empty field has no record and gets the input's line height.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
0 commit comments