当我在-drawRect中绘制字符串时,为什么换行符不起作用?

时间:2010-03-29 10:07:50

标签: iphone cocoa-touch

Newline字符在UIView的draw rect中不起作用?有人可以帮忙吗?

 - (void)drawRect:(CGRect)rect
{

CGContextRef context = UIGraphicsGetCurrentContext();
UIFont * f = [UIFont systemFontOfSize:20];
[[UIColor darkGrayColor] set];
 CGRect b = [self bounds];

NSString * text = @"hi \nr u";

CGSize sz = CGSizeMake(150,200);

CGContextScaleCTM(context, b.size.width/sz.width, b.size.height/sz.height);
[text drawAtPoint:CGPointMake(0,0) withFont:f];

}

1 个答案:

答案 0 :(得分:4)

考虑使用drawInRect:withFont:代替drawAtPoint:withFont:,因为后者仅支持单行文字。