Search code examples
iosswiftnsstringuilabelnsattributedstring

UILabel issue with sum


My UILabel has a long text (text is different for different situations and languages, I use AttributedString), it ends with amount. Smth like:

This amount will be taken from your account: 12.00 $

Label has numberOfLines = 0, so sometimes text looks like

This amount will be taken from your account: 12.00 
$

And it's very important not to set line break between 12.00 and $, because it looks very bad. Are there any special symbol like   in html, so I can put it between 12.00 and $ ? So the UILabel never put like break between 12 and $?

So what I want is:

This amount will be taken from your account: 
12.00 $

or

This amount will be taken from your account: 12.00 $

or

This amount will be taken from 
your account: 12.00 $

but it should never be like

This amount will be taken from your account: 12.00 
$

Solution

  • Are there any special symbol like   in html, so I can put it between 12.00 and $ ?

    For this case, you can use the nobreak space character \u00a0

    Example:

    let text = "This amount will be taken from your account: 12.00\u{00a0}$"
    

    enter image description here