2010-04-26 4 views
1

je rencontre un problème comme suit: J'ai un NSString affiché dans une UILabel en plusieurs lignes avec le mode WordWrap = UILineBreakModeWordWrap, rendu en 2 lignes NSString * myText = @ "Je suis ici travailler".Comment obtenir le lenth de chaque ligne du texte lorsque wordwrap est considéré comme

"Je suis ici_" // La ligne 1. _ est vide. "Travail" // Ligne 2.

Y at-il de toute façon pour moi d'obtenir la largeur de la sous-chaîne "Je suis ici"? et aussi pour la 2ème ligne 'Travail'

Si c'est difficile, comment puis-je savoir quelle partie de la chaîne entière est dans la ligne 1? et quelle partie est dans la ligne 2?

merci d'avance.

Répondre

3

Regardez les ajouts UIKit à NSString:

(CGSize)sizeWithFont:(UIFont *)font 
//Returns the size of the string if it were to be rendered with the specified font on a single line. 

(CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size 
// Returns the size of the string if it were rendered and constrained to the specified size. 

(CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode 
//Returns the size of the string if it were rendered with the specified constraints. 
Questions connexes