如何检测UILabel中的省略号?

时间:2013-03-21 06:00:38

标签: ios objective-c uilabel detection

我在Objective C上编程。我有一个UITableViewUILabel个。如何检测UILabel中的省略号?

3 个答案:

答案 0 :(得分:8)

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

<强>更新

如果标签有行,则计算行数并检查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");

希望这会对你有所帮助。

答案 1 :(得分:-1)

NSString *str = @"Hello this is the ...";
NSRange range = [str rangeOfString:@"..."];
if (range.location>0 && range.length == 3) {
    //Found
}

希望这会对你有所帮助。

答案 2 :(得分:-1)

 UILabel *lbl ;
 lbl.text = @"Hello..World.";
 NSString * charToCount = @".";
 NSArray * array = [lbl.text componentsSeparatedByString:charToCount];
 if([array count] >= 3)
    NSLog(@"Found");
 else 
    NSLog(@"Not Found");

希望它能帮到你......

相关问题