CGContextShowTextAtPoint deprecated - what shall I

2019-02-12 02:47发布

The following will be considered as deprecated in iOS 7: CGContextSelectFont, CGContextShowTextAtPoint. What should I use instead?

2条回答
兄弟一词,经得起流年.
2楼-- · 2019-02-12 03:16

//begin graphic context 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();
查看更多
beautiful°
3楼-- · 2019-02-12 03:21

You can use [yourString drawAtPoint:aPoint withAttributes:dictOfAttributes];

Docs for that here.

Or you could just add a UILabel to your view hierarchy.

查看更多
登录 后发表回答