简体   繁体   中英

UITextView right to left Unicode \u202B not working

I am essentially making a teleprompter app and I need a UITextView to display right to left for EVERY line.

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

This is not working. I need this to read

" erehT olleH" " kraM si eman yM"

I understand that I also need fonts that are upside down etc.. I need to get this part fixed first. Thanks.

The notation \‫ denotes the Unicode character U+202B is RIGHT-TO-LEFT EMBEDDING, which does not affect the writing direction of characters with strong directionality, such as Latin letters.

The character U+202E RIGHT-TO-LEFT OVERRIDE ( \‮ ) forces right-to-left writing direction, overriding the inherent directionality of characters. To end its effect, use the U+202C POP DIRECTIONAL FORMATTING character:

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

This has little to do with fonts. The rendering engine is supposed to handle some characters like “(” using mirrored symbols, eg so that “(foo)” gets rendered as “(oof)” and not “)oof(” in right-to-left writing. But generally, no mirroring is involved; letters remain the same, they just run right to left.

If you actually want to have text mirrored, you need something completely different (a transformation).

This is the logic for reversing the string... I hope this helps you... Just append this string in your 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM