Home / IOS Development / swift – iOS 13: How can I adjust the leading / down / height of a custom font in UIKit / SwiftUI

swift – iOS 13: How can I adjust the leading / down / height of a custom font in UIKit / SwiftUI



I use a custom font and somehow the rendering screws up the line height, potentially due to misconfigured descent or leading (?), so that g and j are truncated in the last line of the rendered text. I think there may be a problem with this specific font, because Sketch also exposes similar problems with the current font, but I feel that I do not understand quite enough about typographic measurements or fonts. I found this Apple documentation page on typographic concepts quite insightful.

Reproduced label revealing the cut

I looked at the script with the test version of FontLab, which I have used for the first time btw ̵

1; so I have no idea what I’m looking at. It seems that g goes below the configured descent, which seems to be what the last line is. (?) (See: Drawing view in FontLab, which shows the descent of g)

Via lineSpacing I could adjust the distance between just the lines themselves to fix this in the first lines. I know iOS 14 is going to provide a way to change that leading of a Text and SwiftUI. But I have to target iOS 13, so it does not help.

I have also tried SwiftUI Text, and normal UILabel.text and UILabel.attributedText with a custom paragraph style, but nothing I adjust there seems to reduce the problem. The view does not even cut. Just putting upholstery in the frame does not help at all. It increases the distance, but g and j are still cut.

What can I do? Underclass UILabel and overwrite intrinsicContentSize to add a little extra space, when it’s ag and ji last line? It feels a) dirty and b) given that padding did not help, can it not solve the problem?

Is the font itself the problem here? Can I patch the font in any way without making it worse?

Is there any way to change the font’s leading or downward height when using lower level APIs? Seems like I could go down to CoreText, like CTFontCreateCopyWithAttributes(_:_:_:_:) is a candidate, if I could only change via attributes the leading, line position or descent? Can or monkey-patch / swizzle things without shooting myself in the knee? Should I just file a radar a feedback?


Source link