博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
tableview分割线
阅读量:7131 次
发布时间:2019-06-28

本文共 2058 字,大约阅读时间需要 6 分钟。

默认分割线,左边不到屏幕;     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个像素即可实现;

 

转载于:https://www.cnblogs.com/OIMM/p/8989299.html

你可能感兴趣的文章
byRef 与 byVal
查看>>
QTP对日前控件的处理
查看>>
ES6中的尾递归优化例子
查看>>
(寻求志同道合的兄弟)寻求eclipse插件开发能手
查看>>
斗地主算法的设计与实现(一)--项目介绍&如何定义和构造一张牌
查看>>
前端技术/前端冷知识集锦
查看>>
免费高清视频素材下载网站
查看>>
RGW Usage类解析
查看>>
mouseover、mouseout防止多次触发
查看>>
Linux命令行:rpm 命令参数使用详解
查看>>
expdp数据泵自动备份脚本
查看>>
菲波那切数列
查看>>
java 调用存储过程示例版
查看>>
linux之lvm管理及扩容
查看>>
eclipse 查找接口实现类快捷键
查看>>
awk(二)流程控制,数组
查看>>
归并排序
查看>>
Netmask v. Address Prefix Length
查看>>
我的友情链接
查看>>
Unity3D教程:iTween插件的介绍和用法
查看>>