问题描述
我从。
在 Localizable.strings
已添加myFont=ACS Zomorrod;
(阿拉伯语) &安培; myFont=Armalite Rifle;
(英文)
然后将这些字体置于条件
NSString * myFont = localize(@myFont);
NSString * cpFont = @Armalite Rifle;
if([myFont isEqualToString:cpFont]){
self.myLabel.textAlignment = NSTextAlignmentLeft; //这是英语
} else {
self.myLabel.textAlignment = NSTextAlignmentRight; //这是为阿拉伯语
}
编辑1
此外,您可以myLang=阿拉伯语;
& myLang=english;
在 Localizable.strings
中,然后将代码设为
NSString * myLang = localize(@myFont);
NSString * myActualLang = @english;
if([myLang isEqualToString:myActualLang]){
self.myLabel.textAlignment = NSTextAlignmentLeft; //这是英语
} else {
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.
这篇关于如何将阿拉伯文本设置为右侧,将英文文本设置为同一标签上的左侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!