Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
376 views
in Technique[技术] by (71.8m points)

iphone - RTL shows numbers at the end of lines

Trying to display a hebrew string that starts with a number, always displays the number at the end of the string like so: 1. ??? ???? ?????

but I need the number to be displayed at the right side of the text-

any solution to that?

It happens with UILabel & UITextField & UITextView

and trying to write the number at the left side also produce the same resault.

Playing with combinations of UITextAlignment will doesn't help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You don't need to change any setting on UILabel, just put the character with unicode 0x200F before your string. This is the reason:

In Unicode many characters have a specific directionality, which lets the system know it has to be written, say LTR, like ????. The paragraph usually uses the direction of its first character. That's why your string without the number is typed from right to left automatically.

Now some characters, like numbers, have "weak" directionality, so they basically take that of their surrounding. When you type "1. ?????", the system first sees 1, so takes the usual LTR direction. Changing the alignment won't help, as it just shifts the whole text to right, or center.

To solve this issue, Unicode has two marker characters (LTR: 0x200E, RTL:200F). These are invisible, but dictate the directionality. So while "1. ?????" is...

  1. ?????

if you type "#x200F" + "1. ?????" it will display like this:

?1. ?????


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...