UILabels用不同的字体底部对齐的方法是什么?

Bam*_*a91 8 iphone cocoa-touch uitableview uilabel

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

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

这会使标签的帧对齐(请参见下图),但不幸的是,标签的填充是字体大小的函数.

替代文字

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

谢谢

Bam*_*a91 10

这是我的标签排列的最终代码:

CGRect theFrame = CGRectMake(xPosAdjuster,
    floor(theWordRow.rowHeight - thisWord.lblHeight),
    floor(thisWord.lblWidth),
    thisWord.lblHeight);
UILabel *myLabel = [[UILabel alloc] initWithFrame:theFrame];
...
CGRect newFrame = myLabel.frame;
newFrame.origin.y -= floor(myLabel.font.descender);
myLabel.frame = newFrame;
Run Code Online (Sandbox Code Playgroud)

替代文字


Joo*_*ost 7

您可能需要查看此页面.有关于Apple的文档的信息,但这是我发现的第一个.

所以看起来你必须根据下降器做一些计算UIFont.您可以轻松获取此值,它被定义为属性UIFont.