0

我正在使用Loren Brichter 的快速滚动脚本的稍微定制的版本,我遇到了一个问题,即单元格中的标签在到达单元格末尾时不会停止。当编程表格查看标准方式时,如果textLabelsdetailTextLabels太长,它们会自动切断并在字符串末尾应用三个点以留在单元格内。

我想做完全相同的事情,但我不知道如何实现它。这是我在向表格视图单元格中添加文本时使用的代码:

CGPoint t;
CGPoint d;

t.x = feedImage.size.width + 10 + 12;
t.y = 20;
[textLabel drawAtPoint:t withFont:textLabelFont];

d.x = feedImage.size.width + 10 + 12;
d.y = 39;
[detailTextLabel drawAtPoint:d withFont:detailTextLabelFont];
4

2 回答 2

1

遵循本教程。无缝工作。

于 2011-07-29T21:00:57.677 回答
0

您可以以编程方式(使用大约字符宽度)找出最后两个/三个可见字符。然后把剩下的字符去掉,自己放三个点!对于大写字符,尝试宽度为 16,对于小写,宽度为 12 磅,字体大小为 15。通过反复试验找出正确的数字。

行。这是一个根据字符调整标签高度(对于给定宽度)的函数。变量“width”是标签的宽度,“tempWidth”是正在计算的当前行的宽度。您可以修改此函数以返回末尾带有三个点的截断字符串...

#define smallLetterWidth 12
#define capitalLetterWidth 16
-(int) numRowsForString:(NSString *) inputStr width:(int) width{
int j=0;
numRows=1;
int tempWidth = 0;
while(j<[inputStr length]){
    if([[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember:[inputStr characterAtIndex:j]])
        tempWidth += capitalLetterWidth;
    else
        tempWidth += smallLetterWidth;
     if(tempWidth>width){
        tempWidth = 0;
        numRows++;
        j--;
    }
    else if(tempWidth==width)
    {
        tempWidth = 0;
        numRows++;
    }
    j++;
}
return  numRows;
}

更好的是:-[NSString sizeWithFont:forWidth:lineBreakMode:] 有什么用?

于 2011-07-28T06:47:38.177 回答