xmartlabs / Eureka

Elegant iOS form builder in Swift
https://eurekacommunity.github.io
MIT License
11.78k stars 1.33k forks source link

Multiline LabelRow #2114

Open reenaphilip opened 4 years ago

reenaphilip commented 4 years ago

How to make LabelRow multiline with dynamic height based on the value

I tried setting the number of lines to zero.

        <<< LabelRow {
               $0.title = "Description"
              $0.value = detailViewModel.description
              $0.cell.textLabel?.numberOfLines = 0

        }

But its not working. How can I achieve it ?

mats-claassen commented 4 years ago

For all cell related set up you should use cellSetup or cellUpdate. However that might not fix this issue. LabelRow should work just like any UITableViewCell. It uses the same textLabel. Have you been able to accomplish that on a normal UITableViewCell?

reenaphilip commented 4 years ago

I have added below code

    cellUpdate({ (cell, row) in
            cell.detailTextLabel?.numberOfLines = 0
            cell.detailTextLabel!.translatesAutoresizingMaskIntoConstraints = false
            NSLayoutConstraint.activate([
               cell.detailTextLabel!.leftAnchor.constraint(equalTo: (cell.textLabel?.rightAnchor)!, constant: 15),
                cell.detailTextLabel!.rightAnchor.constraint(equalTo: cell.contentView.rightAnchor, constant: -15),
                cell.detailTextLabel!.bottomAnchor.constraint(equalTo: cell.contentView.bottomAnchor, constant: -15),
                cell.detailTextLabel!.topAnchor.constraint(equalTo: cell.contentView.topAnchor, constant: 15)
                ])
            cell.updateConstraintsIfNeeded()
        })

When the form is created, the this doesn't work. But in the form there is another accordion section. Once I collapse that section automatically the label constraints works. But this label is not in that section. But I need to work it when I create the form.

Attached a video

video.zip

mats-claassen commented 4 years ago

You are adding a new set of constraints on each update pass. Have you tried adding those constraints and setting all of that only in cellSetup? Also try setting cell.setNeedsLayout() after adding the constraints. If you do this in cellSetup, then I think you should not need to call updateConstraintsIfNeeded