uitableviewuiviewautolayoutuikitsnapkit

Why label does not fit inside tableviewcell?


I am using SnapKit for autolaoyut. This is my view:

private func makeIconUI() {
    contentView.addSubview(iconView)
    iconView.snp.makeConstraints { (make) in
        make.leading.equalToSuperview().inset(Dimesion.sidePadding)
        make.height.width.equalTo(19)
        make.top.equalToSuperview().inset(24)
    }
}

private func makeNumberUI() {
    contentView.addSubview(numberLabel)
    numberLabel.backgroundColor = .yellow
    numberLabel.snp.makeConstraints { (make) in
        make.leading.equalTo(iconView.snp.trailing)
        make.top.equalToSuperview().inset(24)
        make.bottom.equalToSuperview()
    }
}

private func makeTitleUI() {
    contentView.addSubview(titleLabel)
    titleLabel.snp.makeConstraints { (make) in
        make.leading.equalTo(numberLabel.snp.trailing)
        make.trailing.equalTo(self.snp.trailing)
        make.top.equalToSuperview()
    }
}

The problem is: Yellow label does not fit fully. The second label pushing on it, but I can fix it.

enter image description here


Solution

  • Am confused.Yellow doesn't fit fully like top of both labels dont match? then remove inset

    
        private func makeNumberUI() {
            contentView.addSubview(numberLabel)
            numberLabel.backgroundColor = .yellow
            numberLabel.snp.makeConstraints { (make) in
                make.leading.equalTo(iconView.snp.trailing)
                make.top.equalToSuperview()
                make.bottom.equalToSuperview()
            }
        }
    

    if logic is horizontally then give it a width like:

    
            view.addSubview(numberLabel)
            numberLabel.backgroundColor = .yellow
            numberLabel.snp.makeConstraints { (make) in
                make.leading.equalTo(iconView.snp.trailing)
                make.width.equalTo(30)
                make.top.equalToSuperview()
                make.bottom.equalToSuperview()
            }