不推荐使用CGContextShowTextAtPoint - 我现在应该使用什么?

rob*_*bok 16 iphone ios ios7 xcode5

在iOS 7中,以下内容将被视为已弃用:CGContextSelectFont,CGContextShowTextAtPoint.我应该用什么呢?

San*_*aus 9

您可以使用 [yourString drawAtPoint:aPoint withAttributes:dictOfAttributes];

这里的文件.

或者您可以只添加一个UILabel视图层次结构.


NSG*_*ode 5

//开始图形上下文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();
Run Code Online (Sandbox Code Playgroud)