Typographic question for space character

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 ?

Answered by endecotp in 815933022

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.

Have you considered attributed strings? That, among many other things, supports tab stops.

@jlilest Thanks for the answer. Yes, I did, but AttributedStrings is really over complex for such a simple thing.

So the simple solution is likely: let largeWidthSpace = " " // Double space

And use it for padding.

Accepted Answer

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.

@endecotp Good point.

Effectively, Unicode 2007 figure space appears to be double char width.

Typographic question for space character
 
 
Q