Note that there are some explanatory texts on larger screens.

plurals
  1. POUILabel default kerning different from CATextLayer
    primarykey
    data
    text
    <p>I have a <code>UILabel</code> with the string 'LA'. I also have a <code>CATextLayer</code> with the same characters in an <code>NSAttributedString</code> assigned to its <code>string</code> property. The kerning in the <code>UILabel</code> is noticeably different from the <code>CATextLayer</code>. Here's the code.</p> <pre><code>- (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]; } </code></pre> <p>Here's <a href="http://tumtiki-github.s3.amazonaws.com/kerning.png">an image</a> of the results.</p> <p>Why is the kerning different between these two methods and what am I doing wrong in the <code>CATextLayer</code> example?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload