在核心图形中绘制文本

时间:2014-05-20 23:55:39

标签: xcode5 core-graphics objective-c++

使用核心图形绘制文本的简单方法是什么?我尝试过CGContextShowTextAtPoint,但它不起作用。

const char s[6]="hello";           
CGContextShowTextAtPoint(UIGraphicsGetCurrentContext(), 50, 50, s, 5);

1 个答案:

答案 0 :(得分:1)

首先,在iOS 7中不推荐使用CGContextShowTextAtPoint。这就是您的代码无效的原因。

但它有很多替代品。我认为[NSString drawAtPoint:aPoint withAttributes:dictOfAttributes]正是您所寻找的。

此外,您可以根据需要参考这些文档获取支持:

https://developer.apple.com/library/mac/#documentation/cocoa/reference/ApplicationKit/Classes/NSString_AppKitAdditions/Reference/Reference.html#//apple_ref/occ/instm/NSString/drawAtPoint:withAttributes

https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/CustomTextProcessing/CustomTextProcessing.html