通过查看有问题的图像
这是刚刚创建动态框架的方法,UILabel
看看这个通过获取高度和宽度,UIlabel
您可以计算整个高度并可以设置行高UITableView.
- (void)setLabeltextWithVerticalAlignTop:(NSString *)theText
{
CGSize labelSize;
// here labelSize is hard-wired but could use constants to populate the size
labelSize = CGSizeMake(210, 129);//this is just for example
//now create the Size from textString SO that We could assign this size to the Label.
CGSize theStringSize = [theText sizeWithFont:lblTitle.font constrainedToSize:labelSize lineBreakMode:lblTitle.lineBreakMode];
lblTitle.frame = CGRectMake(lblTitle.frame.origin.x, lblTitle.frame.origin.y, theStringSize.width, theStringSize.height);
lblTitle.text = theText;
}
调用上述方法要设置描述标签的高度和宽度,您需要传递要在该描述标签上显示的文本。当您获得该标签的高度时,现在您可以在此基础上调整 TableView 行的高度。
编辑:上面的代码只是为 UILabel 创建动态框架
你应该看看这就是你要找的东西......!!!.here你也可以找到一个示例代码。
编辑:当你编辑你的问题时,它只是你需要将其转换为可运行代码的逻辑。
在您的代码中使用以下方法为每一行调用,并在其中进行一些计算。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat rowHeight=0.0;
//here it seems cell have 4 subview added on it.
//so if you could calculate the totla hieht of them.
//so what you really need to do.you just use hieght calculative Method for getting hieght of each of three UILabel
//you need to modify `setLabeltextWithVerticalAlignTop` method .
rowHeight= [self setLabeltextWithVerticalAlignTop:@"pass the correspondingText"];// suppose it returns some hieght for FisrtLabel.
//suppoose here you get the 20.0 height here
rowHeight= rowHeight+[self setLabeltextWithVerticalAlignTop:@"pass the correspondingText"];
// 假设它为 secondUIlabel 返回一些高度。
//suppoose here you get the 40.0 height here
rowHeight= rowHeight+ [self setLabeltextWithVerticalAlignTop:@"pass the correspondingText"];
// suppose it returns some hieght for ThirdUIlabel.
// suppoose here you get the 15.0 height here
//here you have totla height you just need to add some gapping floating value for all of three UIlabel.so that the could not overlap like as.
rowHeight= rowHeight+20.0;
//now you can return that total height
return rowHeight;
}
注意:这只是您需要将其转换为可运行代码的逻辑。我相信这会有所帮助。
我希望它可以帮助你。