In this UIKit app, I have to display numbers (from 1 to 100), in a label., on several lines, with 8 numbers on each line. Order is computed by the app for a specific purpose.
The numbers are separated by space. Label font is Helvetica Neue 15.0.
I want to get them aligned vertically.
So, I have a padding so that they are all the same length of 4.
Problem: the space have smaller width (half in fact) than digits, so alignment is disrupted:
Of course, I can use fixed width fonts (like Menlo), but I've not found one that fits (the zero is barred, which is not looking great in the app).
I have tried using
class func monospacedDigitSystemFont(
ofSize fontSize: CGFloat,
weight: UIFont.Weight
) -> UIFont
and apply to label.text. To no avail as it modifies only digits, not space char.
I have found a workaround, padding with 2 spaces instead of one,
but is there another solution ?
So I am looking for a space character that would have the same width as a digit. There existe thin space (https://en.wikipedia.org/wiki/Whitespace_character) but not larger space.
Does it exist ?
Try character 2007, “figure space”.
Alternatively:
I can use fixed width fonts (like Menlo), but I've not found one that fits (the zero is barred, which is not looking great in the app)
It may be possible to change that; fonts often contain glyph variants such as different shapes of ‘a’ or ‘7’. (I think the Notes app uses the ‘a’ variant). Note these are not different unicode code points. Sorry, I forget how to do this with UIFont.