Sve*_*eta 0 objective-c detection uilabel ios
我正在编程Objective C.我有一个UITableView用UILabel的.如何检测省略号UILabel?
首先,我们可以获得将在标签中呈现的文本的宽度.然后我们可以将宽度与标签的宽度进行比较.如果该宽度超过则则截断字符串,否则不截断.
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)
希望这对你有所帮助.
| 归档时间: |
|
| 查看次数: |
1971 次 |
| 最近记录: |