在iOS7中,UITableViewCell左侧会有默认15像素的空白,这时候,设置SetSeparatorInset:UIEdgeInsetsZero能讲空白去掉。
在iOS8中,设置SetSeparatorInset:UIEdgeInsetsZero不起作用。解决如下,iOS7 与8都可以。
1.设置分割线风格(对于自定义cell,如果cell左边顶部有空隙需要以下代码调整)
在- (void)viewDidLoad里面写
myTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
-(void)viewDidLayoutSubviews
{
// 重写UITableView的方法是分割线从最左侧开始
if ([myTableView respondsToSelector:@selector(setSeparatorInset:)]) {
[myTableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([myTableView respondsToSelector:@selector(setLayoutMargins:)]) {
[myTableView setLayoutMargins:UIEdgeInsetsZero];
}
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
2.设置分割线的颜色:
[myTableView setSeparatorColor:[UIColor colorWithRed:68.0/255.0 green:68.0/255.0 blue:68.0/255.0 alpha:1.0]];
3.隐藏多余cell方法(多余的线)
// 隐藏多余cell
-(void)setExtraCellLineHidden: (UITableView *)tableView
{
UIView *view = [UIView new];
view.backgroundColor = [UIColor clearColor];
[tableView setTableFooterView:view];
}
或者
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
TableViewCell 分割线设置和隐藏多余cell
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
相关阅读更多精彩内容
- 在用到列表的时候经常由于数据源少的问题,底部会留下大量的空白cell以及万恶的分割线。之前的方法是根据数据源动态的...
- 事务控制器有什么作用呢?主要体现在,想实现一个功能,但需要多个接口,这个接口需要上一个接口的数据做参数,我们看数据...
- 一、工作环境准备: Python 2.7 selenium(可以pip安装) Chrome(浏览器插件我用的是谷歌...