0

でプログラミングしていObjective Cます。を持っていUITableViewますUILabel。で省略記号を検出する方法はUILabel?

4

3 に答える 3

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");

これがお役に立てば幸いです。

于 2013-03-21T06:17:06.270 に答える
-1
NSString *str = @"Hello this is the ...";
NSRange range = [str rangeOfString:@"..."];
if (range.location>0 && range.length == 3) {
    //Found
}

これがあなたを助けることを願っています。

于 2013-03-21T06:03:45.683 に答える
-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");

それがあなたを助けることを願っています...

于 2013-03-21T06:14:41.517 に答える