Search code examples
iosxcodefontscentercustom-font

Centering a custom UIButton title with custom font


I'm using some custom fonts I added to my project for the titles of UIButton. I am not able to set my custom fonts in IB, and I've read in some posts that it is not possible yet in the last XCode version, is that right? So, currently, I'm setting the font for the titles programmatically. The point is that, as in IB the font is set to the default, when I set my custom font programmatically it is not centered, I guess because the font I can see in IB for the button has another height and width and this is the size considered to center the title. How could I center the title with my custom font?

Thanks!


Solution

  • The problem came from the custom font, that it introduced some space below characters. This post solved my problem:

    UIButton custom font vertical alignment