I am setting the UILabel
text as below
myLabel.text = name;
What I would like to ask is if the text goes longer I want to show like below
sta开发者_Go百科ckoverflowuserhere.........
How can I done it...
Thanks for any help
If you want your text to truncate at 20 characters you have to do it manually.
NSString *truncatedName = name;
if ([truncatedName length] > 20)
truncatedName = [NSString stringWithFormat:@"%@...", [truncatedName substringToIndex:20]];
myLabel.text = truncatedName;
You need to set the line break mode e.g.
myLabel.lineBreakMode = UILineBreakModeTailTruncation
Have a look @ http://developer.apple.com/library/ios/#documentation/uikit/reference/NSString_UIKit_Additions/Reference/Reference.html#//apple_ref/doc/c_ref/UILineBreakMode for the other ways to handle text that is too long.
精彩评论