开发者

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

开发者 https://www.devze.com 2022-12-25 03:21 出处:网络
the Newline character is not working in draw rect of UIView? can anyone help? - (void)drawRect:(CGRect)rect

the Newline character is not working in draw rect of UIView? can anyone help?

 - (void)drawRect:(CGRect)rect
{

CGContextRef conte开发者_StackOverflow社区xt = 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];

}


Consider using drawInRect:withFont: instead of drawAtPoint:withFont:, as the latter only supports a single line of text.

0

精彩评论

暂无评论...
验证码 换一张
取 消