开发者

Right to left UILabels

开发者 https://www.devze.com 2023-04-09 01:07 出处:网络
I need to display a text using a UILabel ( can\'t use UIWebView ), and it sometimes contains both Hebrew and English. using UILabel\'s default settings the sentence gets 开发者_如何学JAVAmixed up and

I need to display a text using a UILabel ( can't use UIWebView ), and it sometimes contains both Hebrew and English. using UILabel's default settings the sentence gets 开发者_如何学JAVAmixed up and doesn't make sense. I have failed to found a way to make UILabel display text rtl.

Does anybody know anyway to do that, or a code that implements this?


Have a look at this SO, it contains some info on this subject that might help you out. It seems to work for some by adding the code \u200F to the strings to be displayed.

NSString *RTFstr = "1. בבוקר"; //This could be any right-to-left string
NSString *directionalString = [@"\u200F" stringByAppendingString:[note text]];
[someUITextView setString:directionalString];


This will work

-(void)fnForWritingDirection:(UILabel*)label textFor:(NSString *)stringForText{

    NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc] initWithString: [stringForText stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];

    [paragraphStyle setBaseWritingDirection:NSWritingDirectionRightToLeft];

    [attrStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [attrStr length])];

    label.attributedText=attrStr;

}
0

精彩评论

暂无评论...
验证码 换一张
取 消