我制作了一个自定义视图,在这个自定义视图中,我想绘制一个简单的文本。我一直在寻找几个小时,没有找到运气。我在Apple文档中找到的那个很难理解。任何人都可以获得教程的示例或链接吗?感谢。
答案 0 :(得分:3)
这是一个非常简单的例子。您只需要在自定义视图的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];
}