UILabel
에 'LA'라는 문자열이 있습니다. 또한 은 NSAttributedString
에 동일한 문자가 있으며 string
속성에 할당되어 있습니다. UILabel
의 커닝은 CATextLayer
과 현저하게 다릅니다. 여기에 코드가 있습니다.CATextLayer와 다른 UILabel 기본 커닝
- (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];
}
결과는 an image입니다.
왜 이러한 두 가지 방법의 커닝이 다르며 CATextLayer
예에서 잘못된 부분이 무엇입니까? AppKit
또는 UIKit
을가 Core Foundation
에서 유래 아마 때문에, UIKit 사용하여 그리기 문자열 비교하지 않을 때
이 질문에 대한 해결책을 찾았습니까? – haroldcampbell