在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
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 在用到列表的时候经常由于数据源少的问题,底部会留下大量的空白cell以及万恶的分割线。之前的方法是根据数据源动态的...
- 事务控制器有什么作用呢?主要体现在,想实现一个功能,但需要多个接口,这个接口需要上一个接口的数据做参数,我们看数据...
- 一、工作环境准备: Python 2.7 selenium(可以pip安装) Chrome(浏览器插件我用的是谷歌...