【发布时间】:2013-04-30 08:01:18
【问题描述】:
我有以下代码在 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];
【问题讨论】:
-
您应该使用
NSLineBreakByWordWrapping和NSTextAlignmentRight,因为 UI 等效项已被弃用。它们映射到同一个东西,所以它不应该有所作为。 -
"不工作" 对于对齐。我使用了 UI 等效项(NSLineBreakByWordWrapping 和 NSTextAlignmentRight),但仍然无法正常工作!!文本仍在中心。
标签: ios objective-c xcode drawrect