繁体   English   中英

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

[英]Why is the newline character not working when I draw a string within -drawRect:?

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

}

考虑使用drawInRect:withFont:而不是drawAtPoint:withFont: ,因为后者只支持单行文本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM