如何在-drawRect中绘制UILabel:? [英] How to draw an UILabel in -drawRect:?

查看:240
本文介绍了如何在-drawRect中绘制UILabel:?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在这里做所有这些疯狂的坐标系转换,或者是UILabel与-drawRect中的UIImageView绘图不同:?

Must I also do all this crazy coordinate system conversion stuff here, or is an UILabel different from an UIImageView drawing in -drawRect: ?

有一个名为<的方法code> - (void)drawTextInRect:(CGRect)rect for this。

There's a method called - (void)drawTextInRect:(CGRect)rect for that.

但文档说:你不应该打电话直接使用此方法。此方法只能被想要修改标签文本的默认绘图行为的子类覆盖。

BUT the documentation says: "You should not call this method directly. This method should only be overridden by subclasses that want to modify the default drawing behavior for the label’s text."

那么?如何在-drawRect中绘制它??

So? How to draw it then in -drawRect:?

推荐答案

如果在视图中执行自定义绘图,则不得绘制UILabel或其他UI元素,而是绘制文本本身。 NSString有几种在当前上下文中绘制的方法(查看NSString的UIKit扩展文档以获取更多方法):

If you perform custom drawing in your view you must not draw UILabel or another UI element but rather draw text itself. NSString has several methods for drawing in current context (look at NSString's UIKit extension docs for more methods):

- (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font
- (CGSize)drawAtPoint:(CGPoint)point withFont:(UIFont *)font

这篇关于如何在-drawRect中绘制UILabel:?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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