问题描述
我从.
在 Localizable.strings
中添加了 "myFont"="ACS Zomorrod";
(阿拉伯语) &"myFont"="Armalite Rifle";
(英文)
然后让这些字体处于状态
NSString *myFont = localize(@"myFont");NSString *cpFont = @"Armalite Rifle";if ([myFont isEqualToString:cpFont]) {self.myLabel.textAlignment = NSTextAlignmentLeft;//这是英语} 别的 {self.myLabel.textAlignment = NSTextAlignmentRight;//这是阿拉伯语}
编辑 1
你也可以有 "myLang"="arabic";
&"myLang"="english";
在 Localizable.strings
中,然后将代码设为
NSString *myLang = localize(@"myFont");NSString *myActualLang = @"english";如果 ([myLang isEqualToString:myActualLang]) {self.myLabel.textAlignment = NSTextAlignmentLeft;//这是英语} 别的 {self.myLabel.textAlignment = NSTextAlignmentRight;//这是阿拉伯语}
如果我改变字体,我更喜欢第二个选项而不是第一个选项,我将不得不在 NSString *cpFont = @"Armalite Rifle";
行进行更改文件.
I learned how to make English and Arabic project from previous question I asked.
Same Project at github
Now what I did is added a label in this project and wrote "Welcome".
The problem is the layout. When I have English text it is at left side (obviously), but when the Arabic text comes, it should start from right to left. But it is aligned to left only.
Any idea how to deal with such case?
Below are the screenshots...
English
Arabic
Below is what I did...
Added fonts in projects folder (english.ttf & arabic.ttf) as shown here.
In Localizable.strings
added "myFont"="ACS Zomorrod";
(Arabic) & "myFont"="Armalite Rifle";
(English)
and then had those font in condition
NSString *myFont = localize(@"myFont");
NSString *cpFont = @"Armalite Rifle";
if ([myFont isEqualToString:cpFont]) {
self.myLabel.textAlignment = NSTextAlignmentLeft; // this is for English
} else {
self.myLabel.textAlignment = NSTextAlignmentRight; // this is for Arabic
}
Edit 1
Also you could have "myLang"="arabic";
& "myLang"="english";
in Localizable.strings
and then have code as
NSString *myLang = localize(@"myFont");
NSString *myActualLang = @"english";
if ([myLang isEqualToString:myActualLang]) {
self.myLabel.textAlignment = NSTextAlignmentLeft; // this is for English
} else {
self.myLabel.textAlignment = NSTextAlignmentRight; // this is for Arabic
}
I will prefer the second option instead of first as tomorrow if I change the font, I would have to do changes at line NSString *cpFont = @"Armalite Rifle";
in all files.
这篇关于如何在同一标签上将阿拉伯文本设置为右侧,将英文文本设置为左侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!