任何方式底部对齐UILabels与不同的字体? [英] Any way to bottom-align UILabels with dissimilar fonts?

查看:133
本文介绍了任何方式底部对齐UILabels与不同的字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义UITableViewCell的contentView内的UILabels数组。每个标签的字体通过排名来确定大小以形成标签云。在设置单元格(行)的方法中,我遍历将适合该行的单词对象,为每个UILabel设置框架,如下所示:

I have an array of UILabels inside the contentView of a custom UITableViewCell. The font of each label is sized by ranking to form a tag cloud. In the method that sets up the cell (row), I iterate through the word objects that will fit on that line, setting up the frame for each UILabel as follows:

CGRect theFrame = CGRectMake(xPosAdjuster,
    theWordRow.rowHeight - thisWord.lblHeight,
    thisWord.lblWidth,
    thisWord.lblHeight);
UILabel *myLabel = [[UILabel alloc] initWithFrame:theFrame];

这会获得标签的框架对齐(见下图),但不幸的是,

This gets the frames of the labels aligned (see image below), but, unfortunately, the labels have a padding that is a function of the font size.

有没有办法删除UILabel上的填充(边框)和/或计算它,所以我可以相应地调整帧的y pos ?

Is there any way to remove the padding (border) on a UILabel and/or calculate it exactly so I can adjust the y pos of the frames accordingly?

感谢

推荐答案

您可能想看看此网页。有关于苹果的文档的信息,但这是我找到的第一个。

You may want to take a look at this page. There is information on Apple's Docs, however this was the first I found.

所以看起来你需要做一些计算基于 UIFont 。你可以很容易地得到这个值,它被定义为 UIFont 上的属性。

So it looks like you'll have to do some calculation based on the descender of the UIFont. You can easily get this value, it is defined as a property on UIFont.

这篇关于任何方式底部对齐UILabels与不同的字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆