IOS CGContextSelectFont和CGContextShowText不推荐现在使用的内容

IOS CGContextSelectFont和CGContextShowText不推荐现在使用的内容,ios,deprecation-warning,Ios,Deprecation Warning,在iOS7中,不推荐使用CGContextSelectFont和CGContextShowText。弃用消息说我必须使用核心文本,但我不知道这段代码的确切等价物是什么: - (void)drawTextInContext:(CGContextRef)context { CGContextSelectFont(context, [self.font.fontName cStringUsingEncoding:[NSString defaultCStringEncoding]], self.

在iOS7中,不推荐使用CGContextSelectFont和CGContextShowText。弃用消息说我必须使用核心文本,但我不知道这段代码的确切等价物是什么:

- (void)drawTextInContext:(CGContextRef)context
{
    CGContextSelectFont(context, [self.font.fontName cStringUsingEncoding:[NSString defaultCStringEncoding]], self.font.pointSize, kCGEncodingMacRoman);




    CGRect textRect = [self textRectForBounds:self.bounds limitedToNumberOfLines:1];
    CGContextSetTextPosition(context, textRect.origin.x, textRect.origin.y + 5.0f);



    CGContextShowText(context, [self.text cStringUsingEncoding:[NSString defaultCStringEncoding]], strlen([self.text cStringUsingEncoding:[NSString defaultCStringEncoding]]));
}

等效替换:
AttributedString

[txtString drawAtPoint:CGPointMake(x, y)
           withAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"OpenSans"                                                               size:12.0]
                            }];

如何告诉它使用给定的图形上下文?