我使用以下代码在我的应用程序中创建UILabel
和CATextLayer
- (void)viewDidLoad
{
[super viewDidLoad];
self.textLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 90, 20, 20)];
self.textLabel.text = @"1";
self.textLabel.font = [UIFont systemFontOfSize:12];
self.textLabel.backgroundColor = [UIColor redColor];
[self.view addSubview:self.textLabel];
self.textLayer = [CATextLayer layer];
[self.textLayer setString:@"1"];
[self.textLayer setFont:(__bridge CFTypeRef)([UIFont systemFontOfSize:12])];
self.textLayer.backgroundColor = [UIColor greenColor].CGColor;
self.textLayer.frame = CGRectMake(70, 90, 50, 20);
[self.view.layer addSublayer:self.textLayer];
}
结果是
红色的是UILabel
,绿色的是CALayer. I want to know how to vertical align the text in
CALayer , as the
UILabel` 显示。