Quartz 2d / Core Graphics:绘制某些文本的正确方法是什么? [英] Quartz 2d / Core Graphics: What is the right way to draw some text?

查看:76
本文介绍了Quartz 2d / Core Graphics:绘制某些文本的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有一段时间了,在石英2d中似乎有很多方法可以解决这个问题:

I've been at this for awhile, it seems that there's many ways to go about this in quartz 2d:

1)使用核心图形方法绘制文本。 ..

1) Draw text using core graphics methods...

CGContextSelectFont
CGContextSetRGBFillColor
CGContextShowTextAtPoint

等等,这是非常低的水平。

and on and on, which is horribly low level.

2)使用NSString drawAtPoint

2) using NSString drawAtPoint

(到目前为止,我喜欢的方法)

(so far the method I like)

NSString* text = @"Hello";
[text drawAtPoint:point withFont:font];

3)使用UILabel

3) using UILabel

I'我在某处阅读过此书,但不太确定是否可行。但我认为在drawRect中实例化UILabel会非常昂贵,因为drawRect可能被称为无数次。

I've read this somewhere but not too sure if this is possible. but I'm thinking that instantiating a UILabel within drawRect would be pretty costly as drawRect probably gets called a zillion times. ??

我现在可以2。(使用NSString drawAtPoint),但是我想得到一些意见。再次,我试图在drawRect(我将视图子类化)中创建文本,因为我同时也在绘制图形和文本,正确的方法是什么?

I'm doing ok with 2. (using NSString drawAtPoint) for the moment but I wanted to get some opinions. Again, I'm trying to create text within drawRect (I subclassed a view) because I'm also drawing shapes along with text, what is the right way?

谢谢

推荐答案

#1不支持国际字符。因此,如果使用它来绘制用户输入的文本,请不要使用它。

#1 doesn't support international characters. So, don't use it if you use it to draw texts inputted by a user.

因此,请使用#2,除非您绝对确保文本仅包含标准ASCII字符。

So, please use #2 unless you're absolutely sure that the text only contains standard ASCII characters.

这篇关于Quartz 2d / Core Graphics:绘制某些文本的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆