![](/img/trans.png)
[英]Why is color transparent when attempting to draw a colored circle with 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.