开发者

How to set text with ending .... on UILabel

开发者 https://www.devze.com 2023-01-24 07:06 出处:网络
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

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.

0

精彩评论

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