在iOS7中,表格中经常看到的一个情况是如下所示,

解决方法:

1,手写代码控制

 
1
self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
 
1
2
3
4
但是在iOS7之前是没有这个设置,所以要加下判断。以免程序在iOS7之前的环境下运行崩溃。
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
        self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    }

2,nib,通过下图把Separator Insets的模式改为Custom,并且把Left的15改为0

 
 ===========================================
IOS8最新设置方法
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
-(void)viewDidLayoutSubviews {
    
    if ([self.mytableview respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.mytableview setSeparatorInset:UIEdgeInsetsZero];
 
    }
    if ([self.mytableview respondsToSelector:@selector(setLayoutMargins:)])  {
        [self.mytableview setLayoutMargins:UIEdgeInsetsZero];
    }
 
}
 
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
}

方法2:

使用UIAppearance,在程序开始的时候设置全局默认外观,不错的方法

 
1
2
3
4
5
6
7
8
9
[[UITableView appearance] setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
[[UITableView appearance] setSeparatorInset:UIEdgeInsetsZero];
[[UITableViewCell appearance] setSeparatorInset:UIEdgeInsetsZero];
 
if ([UITableView instancesRespondToSelector:@selector(setLayoutMargins:)]) {
    [[UITableView appearance] setLayoutMargins:UIEdgeInsetsZero];
    [[UITableViewCell appearance] setLayoutMargins:UIEdgeInsetsZero];
    [[UITableViewCell appearance] setPreservesSuperviewLayoutMargins:NO];
}

转载 ---> UITableViewCell的分割线的更多相关文章

  1. iOS UITableViewCell的分割线向左延长15(cell长度为全宽)

    iOS7情况下: tableView.separatorInset = UIEdgeInsetsZero; iOS8.9情况下: 首先在viewDidLoad方法中加上如下代码: if ([table ...

  2. 解决UITableViewCell左侧分割线有空白的问题

    ios7中,UITableViewCell左侧会有默认15像素的空白.设置setSeparatorInset:UIEdgeInsetsZero 能将空白去掉. ios8中,setSeparatorIn ...

  3. iOS中 自定义cell分割线/分割线偏移 韩俊强的博客

    在项目开发中我们会常常遇到tableView 的cell分割线显示不全,左边会空出一截像素,更有甚者想改变系统的分割线,并且只要上下分割线的一个等等需求,今天重点解决以上需求,仅供参考: 每日更新关注 ...

  4. facebook design question 总结

    http://blog.csdn.net/sigh1988/article/details/9790337 这里原帖地址: http://www.mitbbs.com/article_t/JobHun ...

  5. iOS开发tips-神奇的UITableView

    概述 UITableView是iOS开发中使用频率最高的UI控件,在前面的文章中对于UITableView的具体用法有详细的描述,今天主要看一些UITableView开发中的常见一些坑,这些坑或许不深 ...

  6. 这里有一篇简单易懂的webSocket 快到碗里来~

    这篇文章是我在学习的时候看到的  刚开始还不是很理解  后来自己百度 又问了一些人  回过头在看这篇文章 真的挺好的 但是原创已经不知道是谁了  转载哦~~~ -------------------- ...

  7. @Transactional注解事务不回滚不起作用无效

     写在前面 数据库Mysql8.0 添加@Transactional注解后事务并未起作用. 修改表的引擎后ok了.(详看下面转载内容) ================================ ...

  8. WYS APP

    UI图:http://modao.io/app/H8eZCQdV1pskjQ7z8bLh 四个tab:我要赛.赛事.运动吧.个人中心 赛事页面 1.主要是个NavigationController 2 ...

  9. UITableViewCell背景色.选中背景色,分割线,字体颜色设置

    1.系统默认的颜色设置 //无色 cell.selectionStyle = UITableViewCellSelectionStyleNone; //蓝色 cell.selectionStyle = ...

随机推荐

  1. ASP.NET MVC another entity of the same type already has the same primary key value

    ASP.NET MVC项目 Repository层中,Update.Delete总是失败 another entity of the same type already has the same pr ...

  2. Searching External Data in SharePoint 2010 Using Business Connectivity Services

    from:http://blogs.msdn.com/b/ericwhite/archive/2010/04/28/searching-external-data-in-sharepoint-2010 ...

  3. 转:EClipse 10个最有用的快捷键

    Eclipse快捷键 10个最有用的快捷键 Eclipse中10个最有用的快捷键组合  一个Eclipse骨灰级开发者总结了他认为最有用但又不太为人所知的快捷键组合.通过这些组合可以更加容易的浏览源代 ...

  4. 用TextPaint来绘制文字

    TextPaint是paint的子类,用它可以很方便的进行文字的绘制,一般情况下遇到绘制文字的需求时,我们一般用TextPaint所提供的方法.开始学习如何绘制文字之前,我们必须要先了解下androi ...

  5. 【读书笔记】iOS-KVC

    一,KVC即键/值编码. 二,KVC的基本调用包括-valueForKey:和-setValue:forKey:. 三,对于KVC,Cocoa自动放入和取出标量值.也就是说,当使用setValueFo ...

  6. oc 字符串

    #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...

  7. IOS开发--常用的基本GDB命令

    gdb不是万能的,可是没有gdb却是万万不能的.这里给大家简单介绍下iOS开发中最基本的gdb命令. po po是print-object的简写,可用来打印所有NSObject对象.使用举例如下: ( ...

  8. iOS开发之网络编程--使用NSURLConnection实现文件上传

    前言:使用NSURLConnection实现文件上传有点繁琐.    本文并没有介绍使用第三方框架上传文件. 正文: 这里先提供用于编码测试的接口:http://120.25.226.186:3281 ...

  9. IOS之UI--自定义按钮实现代理监听点击事件

    前言: Objective-C提供的按钮监听事件的方法是 不含参数的监听方法 [button实例对象 addTarget:self action:@selector(func) forControlE ...

  10. 大家一起和snailren学java-(四)初始化与清理

    初始化和清理,是一个生命周期的起始.在java中,对象的初始化和对象的回收是怎样的呢? 在开发c++的时候,有构造器的概念.即对象的创建,首先默认调用构造器进行初始化.在java中也有“构造器”.ja ...