自定义cell中使用添加多个图片并自适应cell高度(类型于电商平台的商品评价添加图片)
2016-07-04 16:45
423 查看
Demo实例
使用注意事项:
1、根据图片个数,及最大数限制换行和高度计算;
// 计算实际视图高度
+ (CGFloat)getImageAddMoreViewRealHeight:(NSInteger)count maxCount:(NSInteger)countMax
{
CGFloat height = originY + originY;
// 非最后一个时,添加一个添加图片的按钮
NSInteger countButton = (count < countMax ? 1 : 0);
NSInteger countReal = count + countButton;
NSInteger row = countReal / imageRowCount;
row += ((countReal % imageRowCount == 0) ? 0 : 1);
height += (row * sizeImage + (row - 1) * originY);
return height;
}
2、图片数据改变后,刷新tableview
// 刷新数据
// 方法1
[weakSelf.mainTableView reloadData];
// 方法2
[weakSelf.mainTableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
// 方法3
[weakSelf.mainTableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
效果图
![](https://img-blog.csdn.net/20160704163856323?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
![](https://img-blog.csdn.net/20160704164045121?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
![](https://img-blog.csdn.net/20160704164103136?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
使用注意事项:
1、根据图片个数,及最大数限制换行和高度计算;
// 计算实际视图高度
+ (CGFloat)getImageAddMoreViewRealHeight:(NSInteger)count maxCount:(NSInteger)countMax
{
CGFloat height = originY + originY;
// 非最后一个时,添加一个添加图片的按钮
NSInteger countButton = (count < countMax ? 1 : 0);
NSInteger countReal = count + countButton;
NSInteger row = countReal / imageRowCount;
row += ((countReal % imageRowCount == 0) ? 0 : 1);
height += (row * sizeImage + (row - 1) * originY);
return height;
}
2、图片数据改变后,刷新tableview
// 刷新数据
// 方法1
[weakSelf.mainTableView reloadData];
// 方法2
[weakSelf.mainTableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
// 方法3
[weakSelf.mainTableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
效果图
相关文章推荐
- PushbackInputStream
- 2.6 固件升级操作
- MyBatis中Like语句使用方式
- IOS中获取各种文件的目录路径的方法
- 透视变换
- EF Power Tools
- 幂等和高并发在电商系统中的使用
- 码农翻身
- android nfc中Ndef格式的读写
- 分组对称密钥加密算法——DES、3DES(DESede 或 TDES)、AES
- sqlalchemy相关知识
- ie数组不支持indexOf 方法解决
- Dreamweaver链接Access数据库IIS配置站点的注意情况
- UICollectionView实现的标签选择器
- JDBC驱动的连接和数据库的加载
- android NFC开发
- _cdel stdcall
- [原]openstack-kilo--issue(五) neutron-agent服务实际是active的-但是显示为XXX
- java web开发资料
- Android 中开发dip(分辨率)和px(像素)互转