我使用以下方法在自定义单元格中绘制文本,效果很好,但是我发现部分文本丢失了(未在单元格中显示所有文本):

- (void)drawContentView:(CGRect)rect {

    UIColor * textColor = [UIColor blackColor];
    if (self.selected || self.highlighted){
        textColor = [UIColor whiteColor];
    }
    else
    {
        [[UIColor whiteColor] set];
        UIRectFill(self.bounds);
    }

    [textColor set];

    UIFont * textFont = [UIFont systemFontOfSize:16];

    CGSize textSize = [text sizeWithFont:textFont constrainedToSize:rect.size];



    [text drawInRect:CGRectMake(self.frame.size.width-(textSize.width+2  ) ,
                                (rect.size.height / 2) - (textSize.height / 2),
                                textSize.width, textSize.height) withFont:textFont lineBreakMode:NSLineBreakByWordWrapping alignment:NSTextAlignmentRight];


}
谢谢,请指教。

最佳答案

尝试使绘制空间大于textSize.width, textSize.heigh

UIFont * textFont = [UIFont systemFontOfSize:16];

CGSize sizeMe = CGSizeMake(300, rect.size.height*1.5);
CGSize textSize = [text sizeWithFont:textFont constrainedToSize:sizeMe];
[text drawInRect:CGRectMake(self.frame.size.width-(textSize.width+10 ) ,
(rect.size.height / 2) - (textSize.height / 2),
textSize.width, textSize.height+(textSize.height*1.5)) withFont:textFont lineBreakMode:NSLineBreakByWordWrapping alignment:NSTextAlignmentRight];

10-06 01:10