1

I have this code, creating simple UILabel with some text and default font

        self.reviewCountLabel = [[UILabel alloc] initWithFrame:someFrame];
        self.reviewCountLabel.text = @"1231 REVIEWS";
        self.reviewCountLabel.textAlignment = NSTextAlignmentRight;
        self.reviewCountLabel.backgroundColor = [UIColor lightGrayColor];
//        self.reviewCountLabel.font = [UIFont fontWithName:kSTGFontAvantGardeBold size:18];
        [self addSubview:self.reviewCountLabel];

On the screen I get this:

enter image description here

BUT if I uncomment code which add custom font I will get this:

enter image description here

Can someone explain why I have vertical alignment to top here? (or help to solve it)

Community
  • 1
  • 1
user1248568
  • 621
  • 1
  • 9
  • 29

1 Answers1

1

It's probably not aligning to top, but the geometry (ascenders, baselines, etc.) of the new font is simply different from the system font. Not all fonts are as clean as others in this regard.

You can tweak the geometry using Apple's Font Tool Suite, specifically the ftxdumperfuser command. Here is an older SO post with a very detailed description of how to use that tool to fix your issue.

Community
  • 1
  • 1
macserv
  • 3,546
  • 1
  • 26
  • 36