如何检测UILabel中的省略号?

Sve*_*eta 0 objective-c detection uilabel ios

我正在编程Objective C.我有一个UITableViewUILabel的.如何检测省略号UILabel

βha*_*avḯ 8

首先,我们可以获得将在标签中呈现的文本的宽度.然后我们可以将宽度与标签的宽度进行比较.如果该宽度超过则则截断字符串,否则不截断.

UPDATE

如果label有行,则计算行数并检查lablewidth*numofLines

UILabel *lblAppTitle = (UILabel*)[self.view viewWithTag:777];    
CGSize stringSize = [lblAppTitle.text sizeWithFont:lblAppTitle.font];

//Count Number of lines
[lblAppTitle sizeToFit];
int numLines = (int)(lblAppTitle.frame.size.height/lblAppTitle.font.leading);

if (stringSize.width > (lblAppTitle.frame.size.width)*numLines)
    NSLog(@"truncated string");
else
    NSLog(@"did not truncate string");
Run Code Online (Sandbox Code Playgroud)

希望这对你有所帮助.