TableView cell 分割线
2015-06-02 15:42
357 查看
tableView.separatorStyle = UITableViewCellSeparatorStyle.SingleLine
在iOS 6上显示是从左到右的一条线,没有空隙,到了iOS7,8 之后就不是了。不过现在加上几句代码就可以了。
注:之前没发现这个方法时,都是在cell里面加了一个View,然后
self.tableView.separatorStyle =UITableViewCellSeparatorStyle.None,也可以实现同样的效果。现在瞬间鄙视自己了。
在iOS 6上显示是从左到右的一条线,没有空隙,到了iOS7,8 之后就不是了。不过现在加上几句代码就可以了。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { var cell : UITableViewCell! = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell cell.textLabel!.text = ( dataSource[indexPath.section] as! Array<AnyObject>)[indexPath.row] as? String // cell的分割线显示为从左到右.也可以在willDisplayCell这个方法里面显示 if tableView.separatorStyle != UITableViewCellSeparatorStyle.None { if cell.respondsToSelector("setSeparatorInset:") { cell.separatorInset = UIEdgeInsetsZero } if cell.respondsToSelector("setLayoutMargins:") { cell.layoutMargins = UIEdgeInsetsZero } if cell.respondsToSelector("setPreservesSuperviewLayoutMargins:") { cell.preservesSuperviewLayoutMargins = false } } return cell }以上那几句关键的代码也可以移动到以下这个方法里:
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { }
注:之前没发现这个方法时,都是在cell里面加了一个View,然后
self.tableView.separatorStyle =UITableViewCellSeparatorStyle.None,也可以实现同样的效果。现在瞬间鄙视自己了。
相关文章推荐
- Gradle的简介与安装
- Android之Http通信——2.详解Http的消息头与响应头
- 看了这么多少关于设计模式的知识,下面我说说自己的看法吧。
- layer-list多图层叠加效果实现圆角功能 sharp属性详解
- PL/SQL:使用pragma restrict_references限制包权限
- 【RAC】rac环境下的数据库备份与还原
- Linux Kernel: What is the major difference between the buffer cache and the page cache?
- Android初学者冷知识
- Java简单实现Socket非阻塞通信
- android Button美化
- 关闭VS的实时调试器
- Mysql 中view创建
- DSP学习第六篇——Flash 的使用
- 将多个war包打成ear包部署was
- 安装oracle(版本:11G)
- Picasso
- mysql 5.6 升级5.7
- 关于大型网站技术演进的思考(九)--网站静态化处理--总述(1)
- sed&awk
- 运维自动化之批量部署(cobbler)的使用