如何在UITableView Swift 3中更改分隔符高度? [英] How to change separator height in UITableView Swift 3?

查看:439
本文介绍了如何在UITableView Swift 3中更改分隔符高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然这个主题已经有一些答案了。它们都不包括Swift 3,它们是很久以前的。目前在Swift 3中更改UITableView中分隔符高度的最佳方法是什么?

Although there a few answers already on this topic. None of them cover Swift 3 and they are from a long time ago. What is currently the best way to change the separator height in a UITableView in Swift 3?

推荐答案

更新为Swift 3:

Updated for Swift 3:

如果你想改变UITableView分隔符的高度,请使用下面的代码。

你应该将它添加到UITableViewCell方法 awakeFromNib()以避免重新创建。

If you want to change the height of the UITableView separator, use the code below.
You should add it to the UITableViewCell method awakeFromNib() to avoid re-creation.

override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code

    let mScreenSize = UIScreen.main.bounds
    let mSeparatorHeight = CGFloat(3.0) // Change height of speatator as you want
    let mAddSeparator = UIView.init(frame: CGRect(x: 0, y: self.frame.size.height - mSeparatorHeight, width: mScreenSize.width, height: mSeparatorHeight))
    mAddSeparator.backgroundColor = UIColor.brown // Change backgroundColor of separator
    self.addSubview(mAddSeparator)
}

这篇关于如何在UITableView Swift 3中更改分隔符高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆