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