UITableView单元格中有一个UILabel。如果标签有长文本,那么它会在标签中的文本顶部添加一些空格。滚动后,此空间会自动删除。我想最初删除这个空间。我该怎么办。我使用以下代码调整标签高度:
- (void) adjustHeightOfLbl : (UILabel *) lbl : (NSIndexPath *)indexPath {
lbl.numberOfLines = 0;
NSAttributedString *attributedText =
[[NSAttributedString alloc] initWithString:(lbl.text?:@"")
attributes:@{NSFontAttributeName: lbl.font}];
CGRect rect = [attributedText boundingRectWithSize:(CGSize){lbl.frame.size.width, CGFLOAT_MAX}
options:NSStringDrawingUsesLineFragmentOrigin
context:nil];
CGSize size = rect.size;
CGRect newFrame = lbl.frame;
newFrame.size.height = size.height;
lbl.frame = newFrame;
}