2010-03-29 34 views
3

換行符不適用於UIView的繪製?誰能幫忙?爲什麼當我在-drawRect中繪製一個字符串時,換行符不起作用?

- (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]; 

}

回答

4

考慮使用drawInRect:withFont:代替drawAtPoint:withFont:,因爲後者只支持單個文本行。

相關問題