gpt4 book ai didi

iphone - 有什么方法可以将 UILabels 与不同的字体底部对齐吗?

转载 作者:行者123 更新时间:2023-12-03 18:34:45 26 4
gpt4 key购买 nike

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

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

这会使标签的框架对齐(见下图),但不幸的是,标签的填充是字体大小的函数。

alt text

有什么方法可以删除 UILabel 上的填充(边框)和/或精确计算它,以便我可以相应地调整框架的 y 位置?

谢谢

最佳答案

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

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;

alt text

关于iphone - 有什么方法可以将 UILabels 与不同的字体底部对齐吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4542473/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com