[英]core text - draw simple text on a custom view in objective C
I have made a custom view, and in this custom view, I want to draw a simple text. 我做了一个自定义视图,在这个自定义视图中,我想绘制一个简单的文本。 I've been searching for couple hours and find no luck.
我一直在寻找几个小时,没有发现运气。 The one that I've found on Apple documentation is hard to understand.
我在Apple文档中找到的那个很难理解。 Can anyone have a sample or link to tutorial ?
任何人都可以提供示例或教程链接吗? Thanks.
谢谢。
Here is a very simple example. 这是一个非常简单的例子。 You only need to call drawAtPoint:withAttributes: on your string inside drawRect: of your custom view.
您只需要在自定义视图的drawRect:内的字符串上调用drawAtPoint:withAttributes:。
@implementation CustomView {
NSDictionary *attributes;
NSString *theText;
}
-(void)awakeFromNib {
attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:24], NSForegroundColorAttributeName:[UIColor redColor]};
theText = @"This is my text";
}
- (void)drawRect:(CGRect)rect {
[theText drawAtPoint:CGPointMake(5, 5) withAttributes:attributes];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.