CGContextShowTextAtPoint deprecated - what shall I use now?

后端 未结 2 799
无人及你
无人及你 2021-01-04 00:01

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

相关标签:
2条回答
  • 2021-01-04 00:35

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

    Docs for that here.

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

    0 讨论(0)
  • 2021-01-04 00:40

    //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();
    
    0 讨论(0)
提交回复
热议问题