CGContextShowTextAtPoint deprecated - what shall I use now?

10,355

Solution 1

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

Docs for that here.

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

Solution 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();
Share:
10,355

Related videos on Youtube

robibok
Author by

robibok

Updated on June 04, 2022

Comments

  • robibok
    robibok almost 2 years

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

    • Keith Smiley
      Keith Smiley over 10 years
      All iOS beta API changes are under NDA and cannot be discussed here. This is something for the Apple developer forums.