我只是试图在UIView
图层中添加CATextlayer
。但是,根据以下代码,我只能得到CATextlayer
的背景色,并且不显示任何文字,而是显示在UIView
中。只是想知道我错过了什么来显示文本。iPhone CATextLayer不显示其文本
任何人都可以提供提示/示例如何使用CATextlayer
?
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
CATextLayer *TextLayer = [CATextLayer layer];
TextLayer.bounds = CGRectMake(0.0f, 0.0f, 100.0f, 100.0f);
TextLayer.string = @"Test";
TextLayer.font = [UIFont boldSystemFontOfSize:18].fontName;
TextLayer.backgroundColor = [UIColor blackColor].CGColor;
TextLayer.wrapped = NO;
//TextLayer.backgroundColor = [UIColor blueColor];
self.view = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)];
self.view.backgroundColor = [UIColor blueColor];
[self.view.layer addSublayer:TextLayer];
[self.view.layer layoutSublayers];
}
return self;
}
我知道这是旧帖子,但这里的问题是您将textlayer添加到您手动创建的视图中,但未将视图添加到当前视图。 – GeneCode 2017-01-05 05:27:52