8

I have custom fonts in my project. But i detected some of the fonts that comes also with XCode have the same problem. For unknown reason the if i set accents to a capital letter (which is very common in Spain, like Álgreba) the top of the text is cutting of.

enter image description here

For other fonts is more clear since i can't even see half accent. I can do a trick which is with UILabel setting a height constraint, but this trick doesn't apply to UIButton or to the title of the navigationBar. I tried also in UILabel calling sizeToFiT with no succeed.

Godfather
  • 4,040
  • 6
  • 43
  • 70
  • Have you tried this? http://stackoverflow.com/questions/13225761/custom-font-on-uibutton-title-clipped-on-top-of-word Also, if this does not work, you can add label behind custom button, so that label acts like button title and then add height constraint to label. Not so elegant solution, but it should work. – Flipper Sep 16 '15 at 12:49
  • `button.layer.masksToBounds = false`? – Kevin Jun 29 '17 at 20:15

2 Answers2

8

i had same problem using a button with an image and custom font. this worked out

btn.contentVerticalAlignment = .fill
btn.contentMode = .center
btn.imageView?.contentMode = .scaleAspectFit
mate0
  • 191
  • 4
  • 7
1

I used .center, but now it's .fill that resolves this problem for me. Using the interface builder press the following button:

enter image description here

Display Name
  • 4,502
  • 2
  • 47
  • 63