[Ios] UIButton custom font vertical alignment


I solved the problem adjusting the top content (not the title!) inset.

For example: button.contentEdgeInsets = UIEdgeInsetsMake(10.0, 0.0, 0.0, 0.0);

Good luck!


I've got a UIButton which uses a custom font, which is set when my view loads:

- (void)viewDidLoad
    [super viewDidLoad];    
    self.searchButton.titleLabel.font = [UIFont fontWithName: @"FONTNAME" size: 15.0 ];

The problem I've got is that the font is appearing to float up of the center line. If I comment out this line, the default font appears vertically centered fine. But changing to the custom font breaks the vertical alignment.

I'm getting the same issue on a Table Cell with a custom font too.

Do I need to tell the view somewhere that the custom font is not as tall as other fonts?

EDIT: I've just realized that the font I'm using is a Windows TrueType Font. I can use it fine in TextEdit on the Mac, only a problem with the alignment in my App

So there is no real answer to this, other than edit the font file. Which I don't know how to do and didn't have time, so I just made my pictures narrower, and adjusted the cell to make it look like it was aligned properly.

A dirty little hack I suppose, but it works and it's fine.

This was the only font that caused a problem, so the issue must be with the font file.

It wasn't actually me that concluded this, it was another SO post, but I can't find it anywhere, if I come across it again I'll stick it in the comments.

I think this is the best answer. no playing with ascender, numberOfHMetrics etc... just import-export by Glyphs application and Job done. Thanks to this answer: https://.com/a/16798036/1207684