Why doesn't a newline character work when I draw a line in -drawRect :?

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

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

}

+3
source share
1 answer

Consider drawInRect:withFont:instead drawAtPoint:withFont:, since the latter only supports one line of text.

+4
source

Source: https://habr.com/ru/post/1738936/


All Articles