我以两个“http:// developmenter.apple.com/library/ios/#documentation/uikit/referation/UILabel_Class/Reference/UILabel.html” rel=“Nofolt noreferr”>>UIULabels 显示用户的评论,一个是用户名,另一个是信息。两个标签都有相同的 X,Y 坐标,但信息标签的预设空间与用户名的宽度相等。这一技术有助于我轻松地支持多线信息。
当用户写阿拉伯信件时会出现问题。 阿拉伯语是左方语言的右侧。 这意味着, 我必须在阿拉伯语字符串的 < em> end em > 上添加空格, 而不是开始。 正如您在下面的截图中看到的, 我并没有做出这种区分, 阿拉伯信件也进入了用户名 。 因此, 我如何检测到 UILabel 的文本属性( https:// developer. apple.com/ library/ mac/ # documentation/ Cocoa/ Reference/ Foundation/ Classes/ NSString_ Class/ Reference/ NSstring. html )? rel= “ nofolvey noreferr” >NSString a) 是用右左方语言写成的?
"https://i.sstatic.net/QrKcB.png" alt="arabic"/>
Fail attempt 1: Regex
我试过使用",http://developmenter.apple.com/library/mac/#document/Foundation/Referation/Reference/NSRegularExpression_Class/Reference/Reference.html" rel=“不跟随 noreferrer”>regexes ,但以下函数总是返回每个字符串的错误, 包括阿拉伯语。
@implementation UILabel (position)
- (BOOL) containsArabic
{
NSError* error;
NSRegularExpression* regex = [NSRegularExpression
regularExpressionWithPattern:@"p{Arabic}"
options:0
error:&error
];
return error == nil
&& [regex
numberOfMatchesInString:self.text
options:0
range:NSMakeRange(0, self.text.length)] > 0;
}
@end
Fail attempt 2: NSLocale
- (BOOL) containsArabic
{
NSString *isoLangCode = (NSString*)CFStringTokenizerCopyBestStringLanguage(
(CFStringRef)self.text,
CFRangeMake(
0,
self.text.length
)
);
NSLocaleLanguageDirection direction = [NSLocale lineDirectionForLanguage:isoLangCode];
NSLog(@"++++++");
NSLog(@"%@", self.text);
NSLog(@"%d", direction);
return direction == NSLocaleLanguageDirectionRightToLeft;
}
输出无效 :
2012-05-28 10:59:11.454 [2110:707] MANCHESTER CITY VS MANCHESTER UNITED LIVE HD
2012-05-28 10:59:11.461 [2110:707] 0
2012-05-28 10:59:11.474 [2110:707] ++++++
2012-05-28 10:59:11.477 [2110:707] tak
2012-05-28 10:59:11.484 [2110:707] 0
2012-05-28 10:59:11.511 [2110:707] ++++++
2012-05-28 10:59:11.513 [2110:707] ونهارك سعيد
2012-05-28 10:59:11.520 [2110:707] 3
2012-05-28 10:59:11.704 [2110:707] ++++++
2012-05-28 10:59:11.712 [2110:707] نهارك سعيد
2012-05-28 10:59:11.740 [2110:707] 3
2012-05-28 10:59:11.763 [2110:707] ++++++
2012-05-28 10:59:11.767 [2110:707] i think i am close
2012-05-28 10:59:11.772 [2110:707] 3