简体   繁体   English

表格单元格高度问题iOS?

[英]table cell height issue iOS?

I have custom table view.I have added 4 views in that 我有自定义表格视图,我在其中添加了4个视图

1.ImageView 2.Three labels 1.ImageView 2.三个标签

在此处输入图片说明

Now I want that image should increase in size for multiple devices.For that i have given it below constraints.Proptional height is 176:339 现在我希望该图像可以在多个设备上增加大小,为此我在限制以下给出了它.Proptional height为176:339

在此处输入图片说明

Now in order to increase the height of the image i have increase height of table i used below code. 现在,为了增加图像的高度,我增加了代码下面使用的表格的高度。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    if(!self.customCell)
    {
        self.customCell = [self.tableview dequeueReusableCellWithIdentifier:@"tableCell"];
    }
    CGFloat height;
    height=self.customCell.img_main.frame.size.height;
    height=height+self.customCell.label_one.frame.size.height;
    height=height+self.customCell.label_two.frame.size.height;
    height=height+self.customCell.label_three.frame.size.height;
    height=height+self.customCell.dev_name.frame.size.height;
    NSLog(@"height is %f",self.customCell.img_main.frame.size.height);

    return height;
}

The heigh of image is always 176 which i set in interface builder for 4 inch screen. 图像的高度始终为176,这是我在4英寸屏幕的界面生成器中设置的。

Why the height of both images & table view cell is not increasing ? 为什么图像和表格视图单元格的高度都没有增加?

This is for your second question, if you want to change the image view's height base on the image it display, i suggest to use Height Constraint instead of Proportional Height Constraint, the calculation will be easier. 这是您的第二个问题,如果要基于显示的图像更改图像视图的高度,我建议使用“高度约束”而不是“比例高度约束”,则计算会更容易。 When you get the image, and know the image size, so you calculate and get the size of the image view, and then update the Height Constrains. 在获取图像时,知道图像的大小,因此可以计算并获取图像视图的大小,然后更新“高度约束”。 Done. 做完了

drag the constraint to your cell 将约束拖动到您的单元格

在此处输入图片说明

update the constraint when image setted 设置图像时更新约束

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    CustomeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellId" forIndexPath:indexPath];
    cell.image = image;
    cell.imageViewHeightConstraint.constant = [self calcuteSizeWithImage:image]; //you need to do the calculation yourself
    return cell;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM