美文网首页
iOS每个cell之间增加间距

iOS每个cell之间增加间距

作者: 忆一曲肝肠断 | 来源:发表于2020-05-01 09:07 被阅读0次

iOS每个cell之间增加间距,有时候UI为了美观,常常在cell之间增加间距,下面介绍几种方法。
方法一,每个分区只显示一行cell,分区头当作你想要的间距(注意,从数据源数组中取值的时候需要用indexPath.section而不是indexPath.row)

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return yourArry.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return cellSpacingHeight;
}

方法二,在cell的contentView上加个稍微低一点的view,cell上原本的内容放在你的view上,而不是contentView上,这样能伪造出一个间距来
方法三,自定义cell,重写setFrame:方法

- (void)setFrame:(CGRect)frame
{
    frame.size.height -= 20;
    [super setFrame:frame];
}

是不是很简单,每天更新小功能,记得点赞加关注哦

相关文章

网友评论

      本文标题:iOS每个cell之间增加间距

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