I want to determine the writing direction of a string so that I can render Right-to-Left languages such as Arabic correctly in a CALayer.
so I have this method
Since UITextAlignment is deprecated, here's an NSString category with NSWritingDirection:
- (NSWritingDirection)alignment{
if (self.length) {
NSArray *rightLeftLanguages = @[@"ar",@"he"];
NSString *lang = CFBridgingRelease(CFStringTokenizerCopyBestStringLanguage((CFStringRef)self,CFRangeMake(0,self.length)));
if ([rightLeftLanguages containsObject:lang]) {
return NSWritingDirectionRightToLeft;
}
}
return NSWritingDirectionLeftToRight;
}