Objective c 核心文本-在objective C中的自定义视图上绘制简单文本
我制作了一个自定义视图,在这个自定义视图中,我想画一个简单的文本。我已经找了几个小时了,但没有找到运气。我在苹果文档中发现的一个很难理解。任何人都可以有一个示例或教程链接吗?谢谢。这里有一个非常简单的例子。您只需要在自定义视图的drawRect:内的字符串上调用drawAtPoint:withAttributes:Objective c 核心文本-在objective C中的自定义视图上绘制简单文本,objective-c,Objective C,我制作了一个自定义视图,在这个自定义视图中,我想画一个简单的文本。我已经找了几个小时了,但没有找到运气。我在苹果文档中发现的一个很难理解。任何人都可以有一个示例或教程链接吗?谢谢。这里有一个非常简单的例子。您只需要在自定义视图的drawRect:内的字符串上调用drawAtPoint:withAttributes: @implementation CustomView { NSDictionary *attributes; NSString *theText; } -(void
@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];
}
这是一个非常简单的例子。您只需要在自定义视图的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];
}
这是一个非常简单的例子。您只需要在自定义视图的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];
}
这是一个非常简单的例子。您只需要在自定义视图的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];
}
大多数人只会添加一个
UILabel
子视图。如果您真的想进入绘图文本的杂草中,请参阅。大多数人只需添加UILabel
子视图。如果您真的想进入绘图文本的杂草中,请参阅。大多数人只需添加UILabel
子视图。如果您真的想进入绘图文本的杂草中,请参阅。大多数人只需添加UILabel
子视图。如果您确实想深入到绘图文本的杂草中,请参见。