tableview分割线
默认分割线,左边不到屏幕;
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个像素即可实现;
tableview分割线的更多相关文章
- 解决tableView分割线左边不到边的情况
//解决tableView分割线左边不到边的情况// if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {// ...
- tableView 分割线的处理
有时候根据UI设计图的需要我们需要对原生的TableView分割线做靠左,靠右的操作 在下面这个方法中实现即可. - (void)tableView:(UITableView *)tableView ...
- TableView分割线从顶端开始
如果什么都不设置的话 分割线是从cell.textlabel处开始的 如果加上 [_myTableView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0) ...
- oc TableView 分割线(separator)部分显示问题
问题:当TableView的cell不能显示完整个屏幕(屏幕有剩余),则没有显示cell的地方也会显示分割线,这不是我们想要的,正常情况下,如果没有cell则应没有分割线.如下图所示:左图为遇到问题, ...
- iOS tableView分割线高度自定义
1.系统自带的集中分割线的形式 myTableView.separatorStyle=UITableViewCellSeparatorStyleNone;(这个是去掉所有分割线)可以通过这个来设置 2 ...
- swift 一句代码补全tableView分割线
1.swift实现分割线补全 swift一个大进步,只要设置tableView.separatorInset = UIEdgeInsets.zero即可补全分割线, 2.OC实现分割线补全 而在OC中 ...
- tableview 分割线置最左边的解决方法
首先在viewDidLoad方法加入以下代码: if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) { [se ...
- iOS-修改TableView分割线样式
实现代码: myTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; 有三种样式: UITableViewCellS ...
- 模拟器的tableView的分割线不显示
只有iOS9和iPhone6 plus模拟器上TableView分割线不会显示. 原因: 由于iPhone6 plus的分辨率较高,开发的时候同常都使用command + 3 或者 command + ...
随机推荐
- Hadoop数据分析平台项目实战(基于CDH版本集群部署与安装)
1.Hadoop的主要应用场景: a.数据分析平台. b.推荐系统. c.业务系统的底层存储系统. d.业务监控系统. 2.开发环境:Linux集群(Centos64位)+Window开发模式(win ...
- Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#<Object>‘的解决方法
发现问题 运行一下以前的一个Vue+webpack的 vue仿新闻网站 小项目,报错 由于自己vue学习不深入,老是这个报错,找了好久(确切的说是整整一下午^...^)才找到原因 -v- Uncau ...
- lua生成UUID
百度云盘地址: https://pan.baidu.com/s/1zo__vSeDGaHOvCJLyzHwvA GitHub地址: https://github.com/bungle/lua-rest ...
- haoi2018
题解: 题目相对其他省难一点 不过弱省省选知识点都这么集中的么.. 4道数学题... 1.[HAOI2018]奇怪的背包 这题考场做就gg了... 其实我想到了那个性质.. 就是这个一定要是gcd的倍 ...
- python全栈开发day81--jsonp
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- JMeter中BeanShell Sampler调试分享
BeanShell脚本 String s = "s"; String y = "y"; boolean result = s.equals(y); vars.p ...
- FastJson 支持配置的PropertyNamingStrategy四种策略
摘要: FastJson默认使用CamelCase,在1.2.15版本之后,FastJson支持配置PropertyNamingStrategy,支持四种策略: CamelCase.PascalCas ...
- springboot(@Service,@Mapper)注解失效导致无法注入service和mapper
给我来灵感的博客:感谢:http://blog.51cto.com/xingej/2053297?utm_source=oschina-app 因为使用了注解的类在使用时是通过new出来的,导致注解注 ...
- CentOS 7 休眠系统
CentOS 7的电源按钮只有关机和重启两项,但是可以用命令来休眠系统: 重启: $ systemctl reboot 退出系统并停止电源: $ systemctl poweroff 待机: $ sy ...
- 【python】TCP/IP编程
No1: [TCP] 客户端 import socket s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.connect(('www.sina ...