How to draw NSString vertically on iPhone?

Chinese characters can be displayed horizontally and vertically. I want users to have both options. How can this be done as an iPhone?

eg.

+-------------------------+         +-------------------------+
| Hello, I am a newbie.   |         |                 b  a  H |
|                         |         |                 i  m  e |
|                         |         |                 e     l |
|                         |   --->  |                 .  a  l |
|                         |         |                       o |
|                         |         |                    n  , |
|                         |         |                    e    |
|                         |         |                    w  I |
+-------------------------+         +-------------------------+
+3
source share
1 answer

Hi "ohho" There is no such method or property with which you can achieve this, but this is possible using jugad (native word) technology. In the following code, I assume that myLabel is a UILabel object that displays the text in the desired form, where the text is taken from myTextField (UITextField object).

CGFloat height= myLabel.font.lineHeight;
int lineCount = myLabel.frame.size.height/height;
float temp = [myTextField.text length]*1.0f/lineCount;
int charPerLine = temp;
charPerLine = (temp > charPerLine)?charPerLine+1:charPerLine;
NSString* original = myTextField.text;
NSString* modifiedString = @"";
for (int i =0; i < lineCount; i++) 
{
    for (int j = charPerLine-1 ; j >=0; j--) 
    {
        NSRange r = NSMakeRange(i+j*lineCount, 1);
        if (r.location < [original length]) {
            modifiedString =[modifiedString stringByAppendingFormat:@"%@ ",[original substringWithRange:r]];
        }
    }
    modifiedString = [modifiedString stringByAppendingString:@"\n"];
}
myLabel.text = modifiedString;  
0
source

Source: https://habr.com/ru/post/1744889/


All Articles