ios - UILabel text alignment when English and Hebrew mixed as text? -
might duplicate not able solve issue.
i have uilabel
having text mixed of english , hebrew. wanted alignment per language means english ltl
, hebrew rtl
. please, help.
text
i bless you, god, creating fruit of vine:
בָּרוּךְ אַתָּה יְיָ אֱלֹהֵֽינוּ מֶֽלֶךְ הָעוֹלָם, בּוֹרֵא פְּרִי הַגָּֽפֶן.
here sample inspired with.
note: don't know how create text, don't know how you'll know what's in english or in hebrew, you'll idea.
nsmutableattributedstring *attrstr = [[nsmutableattributedstring alloc] initwithstring:@"i bless you, god, creating fruit of vine:\n בָּרוּךְ אַתָּה יְיָ אֱלֹהֵֽינוּ מֶֽלֶךְ הָעוֹלָם, בּוֹרֵא פְּרִי הַגָּֽפֶן."]; nsmutableparagraphstyle *englishparagraphstyle = [[nsmutableparagraphstyle alloc] init]; [englishparagraphstyle setalignment:nstextalignmentleft]; nsmutableparagraphstyle *hebrewparagraphstyle = [[nsmutableparagraphstyle alloc] init]; [hebrewparagraphstyle setalignment:nstextalignmentright]; nsrange englishrange = nsmakerange(0, [@"i bless you, god, creating fruit of vine:" length]); nsrange hebrewrange = nsmakerange([@"i bless you, god, creating fruit of vine:" length], [[attrstr string] length] - [@"i bless you, god, creating fruit of vine:" length]); [attrstr addattribute:nsparagraphstyleattributename value:englishparagraphstyle range:englishrange]; [attrstr addattribute:nsparagraphstyleattributename value:hebrewparagraphstyle range:hebrewrange]; [mylabel setattributedtext:attrstr];
you may want before setting uilabel
:
[attrstr addattribute:nsfontattributename value:[uifont whateverfontwithwhateversize] range:nsmakerange(0, [attrstr length])];
Comments
Post a Comment