I have a problem when using UILabel
.
I have two labels here(above images), they have equal font and equal width, textAlignment are both left, they both have 10 characters, but each character have different width so it can't be aligned one by one, I‘m trying to add spacing dynamically but I failed to do that, so how can I fix it? thanks a lot~
The reason it fails is you are using a proportional font, meaning: characters will take up an individual width. An i
will just take a fraction of a m
.
Use a monospaced font, than all characters will have the same width.
label.font = UIFont(name:"Courier", size: 17)
for the same reason Courier and other monospaced fonts are used in code editors.