2017-06-23 66 views
0

虽然这个主题已经有几个答案。他们都没有涉及斯威夫特3,他们很久以前。什么是当前最好的方法来更改Swift 3中UITableView中的分隔符高度?如何更改UITableView Swift 3中的分隔符高度?

+0

您可以使用单元格作为分隔符并设置separatorCell高度。就像细胞分离器细胞-... – tomfriwel

+0

检查separatorInset –

回答

3

更新了斯威夫特3:

如果你想改变的UITableView分离器的高度,使用下面的代码。
您应该将其添加到UITableViewCell方法awakeFromNib()以避免重新创建。

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) 
} 
+0

你是伟大的人:)Teşekkürler!! –

+0

嘿 - 这实际上是在单元格内放置了一个UIView,给出了一个更厚的分隔符的外观,但实际上它只是占用了单元格内的空间。有没有办法真正增加分离器的厚度? – richc

-2

试试这个斯威夫特3:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: YOUR_CELL_IDENTIFIER, for: indexPath) as! yourTableViewCell 

    let viewSeparatorLine = UIView(frame:CGRect(x: 0, y: cell.contentView.frame.size.height - 5.0, width: cell.contentView.frame.size.width, height: 5)) 
    viewSeparatorLine.backgroundColor = .red 
    cell.contentView.addSubview(viewSeparatorLine) 
    return cell 
} 
+0

的值应答不起作用 – SmedleyDSlap

相关问题