有时我们使用tableviewcell展示数据时,接受到的数据会超出我们初始化时设定的cell高度,这时我们就需要自适应cell的高度了.下面是返回cell高度的代码
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
luckNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 40, kScreenWidth - 90, 40)];
NSString *str = [[dataArray[indexPath.row] objectForKey:@"numbers"] componentsJoinedByString:@","];
luckNumberLabel.text = [NSString stringWithFormat:@"您的幸运号: %@",str];
luckNumberLabel.font = FONT(13.0);
luckNumberLabel.lineBreakMode = NSLineBreakByCharWrapping;
luckNumberLabel.numberOfLines = 0;
//自适应高度
CGRect txtFrame = luckNumberLabel.frame;
luckNumberLabel.frame = CGRectMake(80, 55, kScreenWidth - 90, txtFrame.size.height = [luckNumberLabel.text boundingRectWithSize:CGSizeMake(txtFrame.size.width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:[NSDictionary dictionaryWithObjectsAndKeys:luckNumberLabel.font,NSFontAttributeName, nil] context:nil].size.height);
luckNumberLabel.frame = CGRectMake(80, 40, kScreenWidth - 90, txtFrame.size.height);
return luckNumberLabel.maxY + 50;
}
deepin20怎么新增字体? deepin20安装字体的教程
Linux如何给文件权限? linux给文件添加可执行权限的技巧
deepin20桌面图标样式怎么修改? deepin更换图标主题的技巧
virtualbox打不开虚拟机怎么办? linux无法访问virtualbox的解决办法
deepin怎么注销系统? deepin系统注销与切换用户的方法
Manjaro linux怎么调鼠标速度? Manjaro鼠标设置光标速度的技巧