为什么在 iOS 中为 UIButton 设置字体为 Hiragino Kaku Gothic 会导致基线偏高?

基线看起来偏高的原因一方面是字体本身下降部(descender)长度不一,另一方面……Storyboard 的确是坨屎。如果坚持要使用 Storyboard,可以用 Fonts - Apple Developer 工具来更改下降部高度,方法详见 Custom iOS fonts and how to fix the vertical position problem

另一方面也可以更改 UIButton 的 contentEdgeInsets,强行将字体向下推出相当于其下降部高度的距离,比如

myBtn.contentEdgeInsets = UIEdgeInsetsMake(1.8f, 0.0f, -1.8f, 0.0f);

原理可参见 iOS Development: You're Doing It Wrong: You're Doing It Wrong #2: Sizing labels with -[NSString sizeWithFont:...]
原发布于 https://www.zhihu.com/question/21080554/answer/17120019