自定义UITableView的Seperator

在默认配置中 ,UITableView的Cell之间的Seperator左边总是空出一块,即使在Storyboard中设置为0 ,也没有效果

需要在代码中进行配置,在ViewController中实现如下方法

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

{

// Remove seperator inset

if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {

[cell setSeparatorInset:UIEdgeInsetsZero];

}

// Prevent the cell from inheriting the Table View‘s margin settings

if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {

[cell setPreservesSuperviewLayoutMargins:NO];

}

// Explictly set your cell‘s layout margins

if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {

[cell setLayoutMargins:UIEdgeInsetsZero];

}

}

如果所有的界面都是如此风格,也可以通过UIAppearance 统一配置

// iOS 7:

[[UITableView appearance] setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];

[[UITableView appearance] setSeparatorInset:UIEdgeInsetsZero];

[[UITableViewCell appearance] setSeparatorInset:UIEdgeInsetsZero];

// iOS 8:

if ([UITableView instancesRespondToSelector:@selector(setLayoutMargins:)]) {

[[UITableView appearance] setLayoutMargins:UIEdgeInsetsZero];

[[UITableViewCell appearance] setLayoutMargins:UIEdgeInsetsZero];

[[UITableViewCell appearance] setPreservesSuperviewLayoutMargins:NO];

}

原文链接:http://stackoverflow.com/questions/25770119/ios-8-uitableview-separator-inset-0-not-working

时间: 2024-08-13 15:25:48

自定义UITableView的Seperator的相关文章

纯代码实现自定义UITableView的cell

纯代码实现自定义UITableView的cell 新建一个继承自UITableViewCell的类 重写initWithStyle:reuseIdentifier:方法,在里面实现: 添加所有需要显示的子控件(不需要设置子控件的数据和frame,子控件要添加到contentView中) 进行子控件一次性的属性设置(有些属性只需要设置一次, 比如字体\固定的图片) BNPSettingCell.h文件: /*本代码实现自定义cell的分隔线*/ #import <UIKit/UIKit.h> @

IOS 自定义UITableView

根据不同需要,需要使用tableview的结构,但是里面每一个cell,又需要自己的样式,所以学习了一下怎样把自己定义的cell加到tableview里面 首先要自己创建一个类,继承UITableViewCell,然后新建一个空的xib文件,并在class属性设置为对应的类名 代码部分: <pre name="code" class="objc"> #import "SettingViewController.h" #import &

自定义UITableView显示不全

我在开发过程中,遇到了自定义UITableView显示不全的情况,有两行cell始终拉不到底部.估计是我自定义cell时改变了cell的高导致的.我的解决办法是让UITableView多显示两行.下面的数组_allAlarmArray是数据源.在UITableView的协议函数中返回几行的函数. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [_al

自定义UITableview自带侧滑删除按钮样式 by 徐

效果如下: 实现原理: 1.打开tableview自带的侧滑删除功能 核心代码: 1 -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 2 { 3 NSLog(@"只能响应这里的编辑方法..."); 4 } 2.自定义UITableViewCell

自定义UITableView各种函数

转自:http://blog.sina.com.cn/s/blog_7e3132ca0100wyls.html 在XCode对应头文件中修改该类所继承的父类: 在对应的.m文件中添加如下代码: 这样就在view上添加了一个tableView,但其样式是默认的,其中的内容也是空白的,而且此时是无法运行的,因为在头文件中添加了UITableViewDataSource和UITableViewDelegate两个类,所以必须设置一些自定义tableView样式的方法,下面列举了一些相关的方法: 设置C

[Xcode10 实际操作]五、使用表格-(8)自定义UITableView单元格Accessory样式(附件图标)

本文将演示如何自定义单元格的附件图标. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] 1 import UIKit 2 3 //首先添加两个协议. 4 //一个是表格视图的代理协议UITableViewDelegate 5 //另一个是表格视图的数据源协议UITableViewDataSource 6 class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSou

iOS开发之自定义UITableView的cell

系统默认的UITableViewCell的每行都有横线(分隔符),就算没有数据也是如此,有时候我们想只在有数据的地方有下划线,可以去除下划线,然后在awarkFromNid方法中使用addsubview的方法加入下划线到UITableViewCell的contentView中.但有些时候我们还要自定义其他类型的Cell. 自定义cell有两种方法,一种是通过xid自定义控件,一种是通过代码自定义cell. 通过xid自定义cell的步骤: 新建一个xib文件描述一个view的内部结构(假设叫做M

IOS自定义UITableView框架(社区风格)

效果展示 · 进入构建结构 首先我们新建一个工程 接下来我们拖进来一个Table View Controller,将Storyboard Entry Point指向我们的Table View Controller.原来的ViewController就可以删除了.效果如图所示 选中Table View Controller,点击上面菜单栏中Editor->Embed in->Navigation Controller 基本的工作我们都做完了,可以讲工程中没用的东西都可以删除了,方便我们进行编写东

自定义UITableview 两种方法

第一: #import "ViewController.h" @interface ViewController () { UITableView *tableview; } @property(nonatomic,strong) NSMutableDictionary *names; @property(nonatomic,strong)NSArray *keys; @end @implementation ViewController -(NSInteger)numberOfSec