84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
不是 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]; }
你的意思是。。就像微博里面那样。。好像每个 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自定义一个数值