我有以下代码在 UITableViewCell 中绘制文本,它可以正常绘制并返回文本,但在 UITableViewCell 的中心。所以我给它右对齐但不工作!
UIColor * textColor = [UIColor blackColor];
if (self.selected || self.highlighted){
textColor = [UIColor whiteColor];
}
else
{
[[UIColor whiteColor] set];
UIRectFill(self.bounds);
}
[textColor set];
UIFont * textFont = [UIFont boldSystemFontOfSize:14];
CGSize textSize = [text sizeWithFont:textFont constrainedToSize:rect.size];
[text drawInRect:CGRectMake((rect.size.width / 2) - (textSize.width / 2),
(rect.size.height / 2) - (textSize.height / 2),
textSize.width,
textSize.height)
withFont:textFont
lineBreakMode:UILineBreakModeWordWrap
alignment:UITextAlignmentRight];