Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGContextShowTextAtPoint deprecated - what shall I use now?

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

like image 621
robibok Avatar asked Aug 06 '13 16:08

robibok


2 Answers

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

Docs for that here.

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

like image 125
Andrew Avatar answered Nov 10 '22 02:11

Andrew


//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();
like image 40
NSGodMode Avatar answered Nov 10 '22 03:11

NSGodMode