最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
ios开发之UItableViewCell自适应高度
时间:2022-06-25 23:36:17 编辑:袖梨 来源:一聚教程网
有时我们使用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;
}
相关文章
- mcjs网页版即点即玩-mcjs极速秒玩入口 10-23
- 超星学习通网页版登录-超星学习通官网入口 10-23
- poki免费游戏大全-poki免费游戏在线畅玩入口 10-23
- mc.js官方在线入口 10-23
- 海角haijiao社区2025全新网址一键直达-海角社区最新官方入口地址 10-23
- 王者荣耀世界体力上限与恢复方法详解 王者荣耀世界体力机制全面解析 10-20