UILabel的垂直对齐算法是什么?
关于 Apple 未能为 UILabel 提供垂直对齐 API 的问题,这里有充足的讨论 >,但是实际的垂直对齐是如何工作的呢?字符串的边界框(参见 sizeWithFont
)是否居中?或者字体的 x 高度(或大写字母高度?),以便无论上升部分和下降部分如何,基线都保持相同?或者什么?
There's ample discussion here on SO about Apple's failure to provide vertical alignment APIs for UILabel
, but how does the actual vertical alignment work? Is the bounding box of the string (cf. sizeWithFont
) centered? Or the x-height of the font (or the cap height?), so that the baseline stays the same regardless of ascenders and descenders? Or what?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

以下是可用于 UILabel 垂直对齐的代码。我没有看到任何苹果公司在向你提供API方面失败了。你必须使用 label.transform = CGAffineTransformMakeRotation (-M_PI/2);您可以完全控制高度/宽度和对齐方式。希望这有帮助..
Here is the code you can use to do vertical alignment of the UILabel. I do not see any apple's failure in providing API to you. You have to use label.transform = CGAffineTransformMakeRotation (-M_PI/2); You have total control on height/width and alignment. Hope this helps..