在iOS7中,不推荐使用CGContextSelectFont和CGContextShowText。弃用消息说我必须使用Core Text,但我不知道这段代码的确切等价:
- (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]]));
}
答案 0 :(得分:0)
等效替代:AttributedString
[txtString drawAtPoint:CGPointMake(x, y)
withAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"OpenSans" size:12.0]
}];