Swift - UITableView里的cell底部分割线左侧靠边
2016-12-08 10:10
399 查看
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// tableview顶部空白
self.automaticallyAdjustsScrollViewInsets = false
tableView = UITableView(frame: CGRectMake(10, 64, UIScreen.mainScreen().bounds.width - 20, 200), style: .Grouped)
tableView.delegate = self
tableView.dataSource = self
tableView.scrollEnabled = false
// tableView.separatorStyle = .None
// tableview设置边框
// 设置边框的宽度
tableView.layer.borderWidth = 1
// 设置边框的颜色
tableView.layer.borderColor = UIColor.whiteColor().CGColor
// 设置UIView的边框为圆角和展现
tableView.layer.cornerRadius = 10
tableView.layer.masksToBounds = true
// 底部分割线左对齐
tableView.separatorInset = UIEdgeInsetsZero
tableView.layoutMargins = UIEdgeInsetsZero
tableView.cellLayoutMarginsFollowReadableWidth = false
self.view.addSubview(tableView)
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell") ?? UITableViewCell(style: .Default, reuseIdentifier: "cell")
cell.separatorInset = UIEdgeInsetsZero
cell.layoutMargins = UIEdgeInsetsZero
cell.preservesSuperviewLayoutMargins = false
return cell
}
PS:有时候只设置tableView和cell的SeparatorInsert和LayoutMargins仍然不能解决这个问题,左边一点距离始终没有办法封闭。
这时需要设置tableView的cellLayoutMarginsFollowReadableWidth,和cell的preservesSuperviewLayoutMargins。
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// tableview顶部空白
self.automaticallyAdjustsScrollViewInsets = false
tableView = UITableView(frame: CGRectMake(10, 64, UIScreen.mainScreen().bounds.width - 20, 200), style: .Grouped)
tableView.delegate = self
tableView.dataSource = self
tableView.scrollEnabled = false
// tableView.separatorStyle = .None
// tableview设置边框
// 设置边框的宽度
tableView.layer.borderWidth = 1
// 设置边框的颜色
tableView.layer.borderColor = UIColor.whiteColor().CGColor
// 设置UIView的边框为圆角和展现
tableView.layer.cornerRadius = 10
tableView.layer.masksToBounds = true
// 底部分割线左对齐
tableView.separatorInset = UIEdgeInsetsZero
tableView.layoutMargins = UIEdgeInsetsZero
tableView.cellLayoutMarginsFollowReadableWidth = false
self.view.addSubview(tableView)
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell") ?? UITableViewCell(style: .Default, reuseIdentifier: "cell")
cell.separatorInset = UIEdgeInsetsZero
cell.layoutMargins = UIEdgeInsetsZero
cell.preservesSuperviewLayoutMargins = false
return cell
}
PS:有时候只设置tableView和cell的SeparatorInsert和LayoutMargins仍然不能解决这个问题,左边一点距离始终没有办法封闭。
这时需要设置tableView的cellLayoutMarginsFollowReadableWidth,和cell的preservesSuperviewLayoutMargins。
相关文章推荐
- Undefined symbols for architecture x86_64
- swift 关于for循环写出多个控件
- swift中的print
- 【swift3.0】【自定义相册】【Photos.framework】
- 【swift3.0】【GCD】
- Swift中的get和set方法
- GitHub第三方资源库整理(Swift篇)
- Swift3.0 Date日期的使用
- 用 Swift 实现轻量的属性监听系统
- Swift Style Guide
- Swift Protobuf 初探 —— 继 XML 后,JSON 也要被淘汰了吗
- swift 尾随闭包
- Swift基础之两种选择星星的评价样式并获取星星的索引值
- Swift基础之两种选择星星的评价样式并获取星星的索引值
- iOS AVPlayer - swift视频播放
- Swift 新的访问控制fileprivate和open
- Xcode8.1 swift3.0 引入Alamofire 3.5.0 支持iOS版本8.0 设置
- Swift中可选类型隐式解包判断空会报错
- Swift学习4--枚举、属性、方法
- swift 学习小笔记之语法