2010-05-11 5 views
3

Les caractères chinois peuvent être affichés horizontalement et verticalement. Je veux laisser les utilisateurs avoir les deux options. Comment cela peut-il être fait dans une vue iPhone?Comment dessiner NSString verticalement sur iPhone?

par exemple.

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

Répondre

0

Salut « ohho » Il n'y a pas cette méthode ou la propriété par laquelle u peut y parvenir mais, il est possible par la technologie jugad (mot natif). Dans le code suivant, je suppose que myLabel est un objet de UILabel qui affiche le texte sous la forme souhaitée, où le texte est pris à partir myTextField (un objet de 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;