繁体   English   中英

如何以编程方式创建这样的 tableview 单元格?

[英]How do I create a tableview cell like this programmatically?

表格视图单元格

如何创建一个像以红色突出显示的单元格一样的表格视图单元格? 我需要以编程方式创建它。 我目前正在使用 Eureka 和 ViewRow 库。

+++ Section("ViewRow Demo")
            <<< ViewRow<MyView>("view") { (row) in
                row.title = "My View Title" // optional
            }
            .cellSetup { (cell, row) in
                //  Construct the view for the cell
                cell.view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 200)) 

            }

要覆盖选择上的突出显示单元格,我使用 selectionBackground 类

    class SelectionView: UIView {

    public override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.YOUR_PREFERED_COLOR.withAlphaComponent(0.3)
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        fatalError("init(coder:) has not been implemented")
    }

}

用法: cell.selectedBackgroundView = SelectionView(frame: cell.frame)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM