UITextView从右到左Unicode \ u202B无法正常工作

时间:2012-10-06 03:45:14

标签: iphone objective-c xcode unicode uitextview

我实际上是在制作一个提示器应用程序,我需要一个UITextView来显示从右到左的每一行。

NSString *textString = @"Hello There\nMy name is Mark";
textView.text = [@"\u202B" stringByAppendingString: textString];

这不起作用。我需要这个来阅读

“erehT olleH” “kraM si eman yM”

我知道我还需要颠倒的字体等等。我需要先修复这部分。感谢。

2 个答案:

答案 0 :(得分:1)

符号\u202b表示Unicode字符U + 202B是RIGHT-TO-LEFT EMBEDDING,它不会影响具有强方向性的字符的书写方向,例如拉丁字母。

字符U + 202E RIGHT-TO-LEFT OVERRIDE(\u202e)强制从右向左书写方向,覆盖字符的固有方向性。要结束其效果,请使用U + 202C POP DIRECTIONAL FORMATTING字符:

'\u202eHello There\nMy name is Mark \u202c'

这与字体无关。渲染引擎应该处理一些字符,如“(”使用镜像符号,例如“(foo)”被渲染为“(oof)”而不是“oof”(从右到左书写。但一般来说。 ,不涉及镜像;字母保持不变,它们只是从右向左运行。

如果您确实希望镜像文本,则需要完全不同的东西(转换)。

答案 1 :(得分:0)

这是扭转字符串的逻辑......我希望这可以帮助你...只需将此字符串附加到textView.text

 NSString *sampleString = @"Hello this is sample \n Hello there";
    NSMutableString *reverseString = [NSMutableString string];
    NSInteger index = [sampleString length];
    while (index > 0) 
    {
        index--;
        NSRange subStrRange = NSMakeRange(index, 1);
        [reverseString appendString:[sampleString substringWithRange:subStrRange]];
    }
    NSLog(@"%@", reverseString);