在网上查了下资料,有两种方法: 方法一,利用Quartz本身的绘图方法: - (void) drawText:(NSString *)text x:(float)x y:(float)y { CGContextRef context =
UIGraphicsGetCurrentCont CGContextSelectFont(context, "Arial", 20, kCGEncodingMacRoman);
CGContextSetTextDrawingM CGAffineTransform xform = CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, 0.0); CGContextSetTextMatrix(context, xform); CGContextSetTextPosition CGContextShowText(context, [text UTF8String], strlen([text UTF8String])); } 方法二,利用NSString本身的drawAtPoint方法 - (void) drawText2:(NSString *)text x:(float)x y:(float)y { UIFont *font = [UIFont fontWithName:@"Arial" size:20]; [text drawAtPoint:CGPointMake(x, y) withFont:font]; } 在UIView class中的darw code - (void)drawRect:(CGRect)rect { CGContextRef context =
UIGraphicsGetCurrentCont
CGContextSetFillColorWit NSString *text = @"Hello World!"; [self drawText:text x:50 y:0]; [self drawText2:text x:50 y:30]; } 这两种方法都可以,但是第二种方法比第一種方法性能差些。 |
怎么在UIView上绘制文本?(How&nb…
最新推荐文章于 2021-12-18 17:04:16 发布