[九九Tips]- http://www.jianshu.com/users/bab86b3e8aa3/latest_articles
设置TableView各个cell之间的间距
最好的做法是:保持cell的Y值不变,cell高度减小.
Snip20160719_6.png
在自定义cell的时候重写下面的方法,就能够拦截所有设置cell frame的操作.
//各个cell间距值为10
- (void)setFrame:(CGRect)frame{
frame.size.height -= 10;
frame.origin.y += 10;
//重写覆盖frame
[super setFrame:frame];
}
Cell左右两侧内边距
同理,设置Cell左右两侧与父控件之间的间距,也可以用这个方法;
Snip20160719_7.png
- (void)setFrame:(CGRect)frame{
frame.size.height -= 10;
frame.origin.y += 10;
//cell左右设置10内边距
frame.origin.x += 10;
frame.size.width -= 20;
[super setFrame:frame];
}