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

标签 iphone cocoa-touch uitableview uilabel

我在自定义 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/

相关文章:

ios - 屏幕方向?

iphone - 无响应的加速度计数据

ios - 为 UIWebView 中的 contenteditable div 禁用自动大写

ios - 如何使用自定义转换在当前上下文中呈现 View Controller ?

ios - 作为自定义 TableView 单元格的 Xib 文件崩溃

ios - VoiceOver 和异步 UITableView

iphone - 使用 sizeWithFont 时的高度 :constrainedToSize:lineBreakMode with NSLineBreakByTruncatingTail

iphone - 浏览器大小 html css

iphone - 在 iPad 上获取平铺图像集(Deep Zoom)

ios - UITableViewCell内容在滚动时丢失