Book Image

Swift by Example

By : Giordano Scalzo
Book Image

Swift by Example

By: Giordano Scalzo

Overview of this book

Table of Contents (15 chapters)

Adding a list


One more feature missing is the ability to create and set a list.

Implementing ListViewCell

As you can imagine, much of the code is just boilerplate, so we won't spend much time on it. Let's start with ListViewCell:

class ListViewCell: UITableViewCell {
    private let title = UILabel()
    
    override func layoutSubviews() {
        super.layoutSubviews()
        setup()
        layoutView()
        style()
    }
}

// MARK: Setup
private extension ListViewCell{
    func setup(){
        title.numberOfLines = 0
        contentView.addSubview(title)
    }
}

// MARK: Layout
private extension ListViewCell{
    func layoutView(){
        layout(title) { view in
            view.top == view.superview!.top + 5
            view.bottom == view.superview!.bottom - 5
            view.left == view.superview!.left + 15
            view.right == view.superview!.right - 10
        }
    }
}

// MARK: Style
private extension ListViewCell{
    func style(){
        contentView.backgroundColor...