iOS 7 中以下内容将被视为过时: CGContextSelectFont, CGContextShowTextAtPoint. 那么我应该使用什么替代方法呢?
[yourString drawAtPoint:aPoint withAttributes:dictOfAttributes];
方法。相关文档请参考这里。或者你也可以在视图层次结构中添加一个UILabel
。//开始绘图上下文 UIGraphicsBeginImageContext(imageSize);
//get the context for coreGraphics
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetTextDrawingMode(ctx, kCGTextFill);
[[UIColor blackColor] setFill];
[@"yourstring" drawAtPoint:CGPointMake(0, 0) withAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Helvetica" size:17]}];
//make image out of bitmap context
UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();