Tôi có một số UILabel
với chuỗi 'LA'. Tôi cũng có một số CATextLayer
có cùng các ký tự trong một số NSAttributedString
được gán cho thuộc tính string
của nó. Các kerning trong UILabel
là đáng chú ý khác nhau từ CATextLayer
. Đây là mã.Mặc định nhãn mặc định khác với CATextLayer
- (void)viewDidLoad
{
[super viewDidLoad];
//
// UILabel
//
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(20, 50, 280, 100)];
label1.text = @"LA";
label1.backgroundColor = [UIColor clearColor];
label1.font = [UIFont fontWithName:@"Futura" size:90.0];
[self.view addSubview:label1];
//
// CATextLayer
//
UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(20, 130, 280, 100)];
label2.backgroundColor = [UIColor clearColor];
CATextLayer *textLayer = [[CATextLayer alloc] init];
textLayer.frame = label2.layer.bounds;
textLayer.contentsScale = [[UIScreen mainScreen] scale];
[label2.layer addSublayer:textLayer];
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"LA"];
CTFontRef aFont = CTFontCreateWithName((__bridge CFStringRef)@"Futura", 90.0, NULL);
[string addAttribute:(NSString*)kCTFontAttributeName value:(__bridge id)aFont range:NSMakeRange(0, [string length])];
textLayer.string = string;
[self.view addSubview:label2];
}
Đây là an image kết quả.
Tại sao sự khác biệt giữa hai phương pháp này và tôi đang làm gì sai trong ví dụ CATextLayer
?
bạn có tìm thấy giải pháp cho câu hỏi này không? – haroldcampbell