解决TableViewCell分割线默认左边间隔15点
2016-01-22 14:09
274 查看
如下初始化可以解决cell默认左边间距问题
_tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
//_tableView.backgroundColor = [UIColor darkGrayColor];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.separatorInset = UIEdgeInsetsZero;
if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {
_tableView.layoutMargins = UIEdgeInsetsZero;
}
[self.view addSubview:_tableView];
然后在UITableView的代理方法中加入以下代码
- (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];
}
}
备注:
1._tableView.separatorInset = UIEdgeInsetsZero; iOS8之前可以直接用这个就可以解决。
2.
if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {
_tableView.layoutMargins = UIEdgeInsetsZero;
} IOS8之后必须加入此代码才可以解决。
_tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
//_tableView.backgroundColor = [UIColor darkGrayColor];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.separatorInset = UIEdgeInsetsZero;
if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {
_tableView.layoutMargins = UIEdgeInsetsZero;
}
[self.view addSubview:_tableView];
然后在UITableView的代理方法中加入以下代码
- (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];
}
}
备注:
1._tableView.separatorInset = UIEdgeInsetsZero; iOS8之前可以直接用这个就可以解决。
2.
if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {
_tableView.layoutMargins = UIEdgeInsetsZero;
} IOS8之后必须加入此代码才可以解决。
相关文章推荐
- 1、React Native 中ES6语法解析
- c语言程序的存储区域与const关键字的使用方法
- ISP基础二
- C语言-函数指针
- FrescoImageUtil的使用
- 临界段CCriticalSection的使用
- 接口继承与实现继承
- iOS Mob短信验证码
- 使用FreeType实现DirectX11的文本输入
- 如何将url作为一个参数放到另一个url中
- opencv:Load Caffe framework models
- 【spring源代码分析】--Bean的解析与注冊
- 邻接矩阵学习
- ubuntu编译安装nginx
- 样式化复选框
- 在Linux上安装Memcached服务
- 判断字符串是否为中文
- 数字证书原理
- ft232rl可以了
- Hive学习1_hive配置遇到的问题:Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%