开发者

How to draw NSString vertically on iPhone?

开发者 https://www.devze.com 2022-12-29 17:20 出处:网络
Chinese characters can be view horizontally and vertically. I want to let users have both options. How can this be done in an iPhone views?

Chinese characters can be view horizontally and vertically. I want to let users have both options. How can this be done in an iPhone views?

e.g.

+-------------------------+         +-------------------------+
| Hello, I am a newbie.   |         |                 b  a  H |
|                         |         |                 i  m  e |
|                         |         |                 e     l |
|                         |   --->  |                 .  a  l |
|                         |         |                       o |
|                         | 开发者_开发百科        |                    n  , |
|                         |         |                    e    |
|                         |         |                    w  I |
+-------------------------+         +-------------------------+


Hi "ohho" There is no such method or property by which u can achieve this but,it is possible by jugad(native word) technology. In the following code i assume that myLabel is an object of UILabel which displays the text in desired form, where the text is taken form myTextField (an object of UITextField).

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

精彩评论

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