Tôi chỉ đơn giản là cố gắng thêm một CATextlayer
trong một lớp UIView
. Tuy nhiên, theo đoạn mã sau, tôi chỉ nhận được màu nền của CATextlayer
được hiển thị trong UIView
, mà không có bất kỳ văn bản nào. Chỉ cần tự hỏi những gì tôi bị mất để hiển thị văn bản.iPhone CATextLayer không hiển thị văn bản của nó
Có ai có thể đưa ra gợi ý/mẫu cách sử dụng CATextlayer
không?
- (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;
}
Tôi biết đây là bài cũ, nhưng vấn đề ở đây là bạn thêm textlayer vào chế độ xem mà bạn đã tạo theo cách thủ công, nhưng bạn không thêm chế độ xem vào chế độ xem hiện tại của mình. – GeneCode