扫码关注官方订阅号
84669人学习
65727人学习
82984人学习
467778人学习
498837人学习
471966人学习
256484人学习
152542人学习
224170人学习
139536人学习
81804人学习
85022人学习
11944人学习
20001人学习
60816人学习
5487人学习
15007人学习
2150人学习
6980人学习
194925人学习
359900人学习
1142人学习
19058人学习
3206人学习
180550人学习
48569人学习
17603人学习
40936人学习
1049人学习
750人学习
32909人学习
不是 heightForRowAtIndexPath: 这个的间距,我指的是cell与cell之间的间距,默认是贴紧的!!!!
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...
你的意思是。。就像微博里面那样。。好像每个 cell 之间有间隙那种么?
笨方法,每个cell 里面设置一点点空白区域啊 X D
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 60.0f } override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { cell.contentView.backgroundColor = UIColor.clearColor() let gapView : UIView = UIView(frame: CGRectMake(0, 10, self.view.frame.size.width, 120)) gapView.layer.backgroundColor = UIColor(red: 1.0f, green: 1.0f, blue: 1.0f, alpha: 1.0f) gapView.layer.masksToBounds = false gapView.layer.cornerRadius = 2.0f gapView.layer.shadowOffset = CGSizeMake(-1, 1) gapView.layer.shadowOpacity = 0.2f cell.contentView.addSubview(gapView) cell.contentView.sendSubviewToBack(gapView) }
每个 cell 高度高一点点(高出你想要的间距),cell 背景设为透明,用自己的 view 作为背景,不填满 cell ,下面空出 你超出的高度
UITableView只能通过间接的方式设置出来。如果想更完美智能地设置cell间距,建议你使用UICollectionView
UITableView
UICollectionView
你用 heightForRowAtIndexPath:多留出一点高度不就好了……
heightForRowAtIndexPath:
可以设置多个section啊,每个section就一条cell,那么cell之间的距离不就变成设置section之间的距离了。section之间的距离不好设么
1楼的办法是最靠谱的,collectionView性能比较可怜,还不如cell多设置一些空白比较划算。
重写cell的setFrame方法
MessageCellSectionMargin自定义一个数值
- (void)setFrame:(CGRect)frame { CGRect cellFrame = frame; cellFrame.size.height = cellFrame.size.height - MessageCellSectionMargin; cellFrame.origin.y = cellFrame.origin.y + MessageCellSectionMargin; frame = cellFrame; [super setFrame:frame]; }
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
扫描下载App
Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
精品班
技术支持
技术咨询
学习群
会员优惠
返回顶部
你的意思是。。就像微博里面那样。。好像每个 cell 之间有间隙那种么?
笨方法,每个cell 里面设置一点点空白区域啊 X D
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
每个 cell 高度高一点点(高出你想要的间距),cell 背景设为透明,用自己的 view 作为背景,不填满 cell ,下面空出 你超出的高度
UITableView
只能通过间接的方式设置出来。如果想更完美智能地设置cell间距,建议你使用
UICollectionView
你用
heightForRowAtIndexPath:
多留出一点高度不就好了……可以设置多个section啊,每个section就一条cell,那么cell之间的距离不就变成设置section之间的距离了。
section之间的距离不好设么
1楼的办法是最靠谱的,collectionView性能比较可怜,还不如cell多设置一些空白比较划算。
重写cell的setFrame方法
MessageCellSectionMargin自定义一个数值