CGContextShowTextAtPoint deprecated - what shall I use now?

て烟熏妆下的殇ゞ 提交于 2019-11-30 16:36:54

问题


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


回答1:


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

Docs for that here.

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




回答2:


//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();


来源:https://stackoverflow.com/questions/18086021/cgcontextshowtextatpoint-deprecated-what-shall-i-use-now

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!