博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS - TableViewCell分割线 --By吴帮雷
阅读量:4522 次
发布时间:2019-06-08

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

千万别小看UI中得线,否则你的设计师和测试组会无休止地来找你的!!(如果是美女还好,如果是恐龙。。。。)

在开发中运用最多的是什么,对,表格--TableView,之所以称作表格,是因为他天生带有分割线。

首先系统带的有如下类型:

typedef NS_ENUM(NSInteger, UITableViewCellSeparatorStyle) {    UITableViewCellSeparatorStyleNone,    UITableViewCellSeparatorStyleSingleLine,    UITableViewCellSeparatorStyleSingleLineEtched   // This separator style is only supported for grouped style table views currently};

有时你要短点的,如同这样:

那你可以这样:

if ([_pinglunTableView respondsToSelector:@selector(setSeparatorInset:)]) {            UIEdgeInsets insets=UIEdgeInsetsMake(0, 53, 0, 0);            [_pinglunTableView setSeparatorInset:insets];        }

也可以完全自己定义自己想要的分割线,但意味着你要自定义 TableViewCell,然后在自定义UITableViewCell中复写- (void)drawRect:(CGRect)rect方法 如:

- (void)drawRect:(CGRect)rect{    CGContextRef context = UIGraphicsGetCurrentContext();    CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor); CGContextFillRect(context, rect);//上分割线     CGContextSetStrokeColorWithColor(context, [UIColor colorWithHexString:@"ffffff"].CGColor);    CGContextSetStrokeColorWithColor(context, [UIColor colorWithHexString:@"ffffff"].CGColor);     CGContextSetStrokeColorWithColor(context, [UIColor colorWithHexString:@"e2e2e2"].CGColor);    CGContextStrokeRect(context, CGRectMake(5, rect.size.height, rect.size.width - 10, 1));//下分割线    CGContextSetStrokeColorWithColor(context, [UIColor colorWithHexString:@"e2e2e2"].CGColor);    CGContextStrokeRect(context, CGRectMake(5, rect.size.height, rect.size.width - 10, 1));}

 

如果要改变颜色,则利用类似[tableView setSeparatorColor:[UIColor redColor]];语句即可修改cell中间分割线的颜色。

如果UI给你一张图片,那么就可以这样:

方法一:

先设置cell separatorColor为clear,然后把图片做的分割线添加到自定义的custom cell上。

方法二:

在cell里添加一个像素的imageView后将图片载入进,之后设置tableView.separatorStyle = UITableViewCellSeparatorStyleNone

转载于:https://www.cnblogs.com/sixindev/p/4538511.html

你可能感兴趣的文章
swift
查看>>
eclipse maven 插件的安装和配置
查看>>
mysql基本知识总结
查看>>
php的zend引擎执行过程 一
查看>>
pycharm 快捷键
查看>>
Linux常用命令
查看>>
AutoFac IoC DI 依赖注入
查看>>
.net中的设计模式---单例模式
查看>>
安装程序工具 (Installutil.exe)22
查看>>
python 学习(pip工具的安装)
查看>>
博客园在我的博客添加点击小心心特效
查看>>
如何简单解释 MapReduce算法
查看>>
从 0 到 1 实现 React 系列 —— 1.JSX 和 Virtual DOM
查看>>
面向接口编程详解(二)——编程实例
查看>>
解决java.lang.NoClassDefFoundError: org/apache/log4j/Level
查看>>
端口号
查看>>
mysql for macOS安装
查看>>
iOS中的KeyChain的用途
查看>>
jquery与checkbox的checked属性的问题
查看>>
HDU5092——Seam Carving(动态规划+回溯)(2014上海邀请赛重现)
查看>>