默认分割线,左边不到屏幕;

    TableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;

三种结构体样式: 
/** 
UITableViewCellSeparatorStyleNone, 没有分割线 
UITableViewCellSeparatorStyleSingleLine, 单线(默认) (左边不到屏幕)
UITableViewCellSeparatorStyleSingleLineEtched 内嵌线 (左边到屏幕)
*/ 分割线从边界开始方法一:
- (void)viewDidLoad {
[super viewDidLoad];
...
...
...
#pragma mark - a 调整view边距
// 1.调整(iOS7以上)表格分隔线边距
if ([self.MyTableView respondsToSelector:@selector(setSeparatorInset:)]) {
self.MyTableView.separatorInset = UIEdgeInsetsZero;
}
// 2.调整(iOS8以上)view边距(或者在cell中设置preservesSuperviewLayoutMargins,二者等效)
if ([self.MyTableView respondsToSelector:@selector(setLayoutMargins:)]) {
self.MyTableView.layoutMargins = UIEdgeInsetsZero;
} } #pragma mark - b 调整view边距
//然后在willDisplayCell方法中加入如下代码:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
#pragma mark - b
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}

方法二:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
...
...
...
#pragma mark - a 调整view边距
//1.调整(iOS8以上)tableView边距(与上面第2步等效,二选一即可)
if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
cell.preservesSuperviewLayoutMargins = NO;
}
//2.调整(iOS8以上)view边距
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
return cell;
} #pragma mark - b 调整view边距
//然后在willDisplayCell方法中加入如下代码:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
#pragma mark - b
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
}

方法三:

系统自带的cell的分割线,满足我们大部分的需求,但在有些情况下,我们需要使用样式二中得cell的分割线样式。 
同时,我们也可以自定义cell的分割线。通过1个像素宽的图片或者view添加到cell中; 
或者设置背景图片为灰色,同时设置cell之间的间距为1个像素即可实现;

 

最新文章

  1. svn 权限配置
  2. Linux下which、whereis、locate、find命令的区别
  3. hbase基本结构
  4. 在wpf窗体上添加用户控件
  5. AFNetworking使用
  6. Linux 学习笔记 更多的bash shell命令
  7. Android_gridVIew
  8. 【产品体验】支付宝Alipay9.0
  9. bzoj2180: 最小直径生成树
  10. 为什么使用Redis
  11. linux查看端口占用
  12. Spring @Resource注解
  13. 201521123060《Java程序设计》第1周学习总结
  14. 基于netfilter和LVM的密码窃取
  15. 利用Google趋势来预测比特币价格
  16. BZOJ.5305.[HAOI2018]苹果树(组合 计数)
  17. Java8 Lambda和Stream的用法
  18. 重写console.log的一些理解
  19. salesforce lightning零基础学习(五) 事件阶段(component events phase)
  20. 转:C# 对委托的BeginInvoke,EndInvoke 及Control 的BeginInvoke,EndInvoke 的理解

热门文章

  1. views.py视图函
  2. 设置git记住用户和密码
  3. WMSYS.WM_CONCAT返回CLOB类型的解决办法
  4. java.lang.OutOfMemoryError: unable to create new native thread
  5. Entity Framework介绍
  6. Apache ActiveMQ 远程代码执行漏洞 (CVE-2016-3088)案例分析
  7. tomcat-会话绑定
  8. 将程序sublime添加到右键菜单中
  9. 桐桐的数学游戏(N皇后)
  10. hive中使用union出现异常数据