美文网首页
优雅的设置TableViewCell间隔

优雅的设置TableViewCell间隔

作者: MccReeee | 来源:发表于2018-04-04 17:00 被阅读211次

其实优雅的也是最简单的方法是直接让UITableView中的cell收缩一点,这样UITableView的底色就是分割线的颜色了,如上图就是橘色。这种方式只需要重写cell的setFrame方法即可

-(void)setFrame:(CGRect)frame
{
    frame.origin.x = 10;//这里间距为10,可以根据自己的情况调整
    frame.size.width -= 2 * frame.origin.x;
    frame.size.height -= 2 * frame.origin.x;
    [super setFrame:frame];   
}
  • 如果此时想要实现圆角也很简单,直接加上
self.layer.masksToBounds = YES;
self.layer.cornerRadius = 8.0;

相关文章

网友评论

      本文标题:优雅的设置TableViewCell间隔

      本文链接:https://www.haomeiwen.com/subject/prflhftx.html