How do I center embedded fonts vertically within UILabels?

浪尽此生 提交于 2019-12-23 01:13:33

问题


In a previous question:

Embedded fonts in iOS: why are they not centered correctly on the y axis?

it was noted that embedded fonts were not being centered vertically in iOS controls.

A solution was proposed there, but that solution only works with buttons. How can we properly center embedded fonts within UILabels?


回答1:


I've had a problem with a custom font in iOS that had very tall glyphs so they were getting clipped by the label. Ended creating my own label subclass with self created CATextLayer. This may sound extreme, but isn't actually that much work, and gives you complete control on positioning, style etc.




回答2:


It's possible that your font has incorrect metrics. Understanding UIFont has a good overview of what each metric means. Compare the font metrics you get from your font to the font metrics for system fonts and see if anything appears significantly wrong.



来源:https://stackoverflow.com/questions/6845795/how-do-i-center-embedded-fonts-vertically-within-uilabels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!