Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 核心文本-在objective C中的自定义视图上绘制简单文本_Objective C - Fatal编程技术网

Objective c 核心文本-在objective C中的自定义视图上绘制简单文本

Objective c 核心文本-在objective C中的自定义视图上绘制简单文本,objective-c,Objective C,我制作了一个自定义视图,在这个自定义视图中,我想画一个简单的文本。我已经找了几个小时了,但没有找到运气。我在苹果文档中发现的一个很难理解。任何人都可以有一个示例或教程链接吗?谢谢。这里有一个非常简单的例子。您只需要在自定义视图的drawRect:内的字符串上调用drawAtPoint:withAttributes: @implementation CustomView { NSDictionary *attributes; NSString *theText; } -(void

我制作了一个自定义视图,在这个自定义视图中,我想画一个简单的文本。我已经找了几个小时了,但没有找到运气。我在苹果文档中发现的一个很难理解。任何人都可以有一个示例或教程链接吗?谢谢。

这里有一个非常简单的例子。您只需要在自定义视图的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];
}

这是一个非常简单的例子。您只需要在自定义视图的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
子视图。如果您确实想深入到绘图文本的杂草中,请参见。