小编Dhe*_*mar的帖子

动态增加UILabel和TableView Cell的高度?

我有一个UITableView,我在其中显示一个自定义单元格.我的单元格我有两个标签和一个视图如下图所示.

在此输入图像描述

我像这样给了左视图的约束

物品标签限制

在此输入图像描述

中心视图约束

在此输入图像描述

正确的观点

在此输入图像描述
我使用bean类来存储两个标签的数据,并将该bean对象添加到一个数组中.我在heightForRowAtIndexPath中使用下面的代码.

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

    // Calculate a height based on a cell
    if(!self.customCell) {
        self.customCell = [self.tableView dequeueReusableCellWithIdentifier:@"thirdcell"];
    }

    // Configure the cell
    Instrument *inst=[arr_instSpecs objectAtIndex:indexPath.row];
    self.customCell.label_item.text=inst.item;
    self.customCell.label_desc.text=inst.desc;


    // Layout the cell

    [self.customCell layoutIfNeeded];

    // Get the height for the cell

    CGFloat height = [self.customCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;

    // Padding of 1 point (cell separator)
    CGFloat separatorHeight = 1;

    return height + separatorHeight;
}
Run Code Online (Sandbox Code Playgroud)

问题是标签的高度和表视图单元都没有增加.我已经解释了一切.我想在标签文本增加时增加标签的大小,并且当标签大小增加时,单元格的高度必须增加.

objective-c row-height uitableview ios swift

15
推荐指数
2
解决办法
3万
查看次数

如何更改iOS中属性字符串的字体?

我在label上添加了属性字符串.我显示的html文本工作正常,但默认情况下它始终显示Times新罗马家族.请告诉我如何更改文本系列.

NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[inst.desc dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
Run Code Online (Sandbox Code Playgroud)

objective-c nsattributedstring ios

-2
推荐指数
2
解决办法
8471
查看次数