Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 有没有办法将UILabel与不同的字体进行底部对齐?_Iphone_Cocoa Touch_Uitableview_Uilabel - Fatal编程技术网

Iphone 有没有办法将UILabel与不同的字体进行底部对齐?

Iphone 有没有办法将UILabel与不同的字体进行底部对齐?,iphone,cocoa-touch,uitableview,uilabel,Iphone,Cocoa Touch,Uitableview,Uilabel,我在自定义UITableViewCell的contentView中有一个UILabel数组。每个标签的字体大小由排名决定,形成标签云。在设置单元格(行)的方法中,我遍历将适合该行的word对象,为每个UILabel设置框架,如下所示: CGRect theFrame = CGRectMake(xPosAdjuster, theWordRow.rowHeight - thisWord.lblHeight, thisWord.lblWidth, thisWord.lblHei

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

CGRect theFrame = CGRectMake(xPosAdjuster,
    theWordRow.rowHeight - thisWord.lblHeight,
    thisWord.lblWidth,
    thisWord.lblHeight);
UILabel *myLabel = [[UILabel alloc] initWithFrame:theFrame];
这会使标签的框架对齐(参见下图),但不幸的是,标签的填充是字体大小的函数

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


谢谢

您可能想看看。有关于苹果文档的信息,但这是我第一次发现


因此,看起来您必须根据
UIFont
的后代进行一些计算。您可以很容易地获得此值,它被定义为
UIFont

上的一个属性。以下是我的最终代码,用于排列标签:

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;

谢谢。这正是我所需要的。对于那些对下降器有问题的人,你可以按照这里的描述编辑你的字体文件:我认为它应该是:newFrame.origin.y+=floor(myLabel.font.downer);