Search code examples
iosiphoneframeworkseureka-forms

ImageView and textfields in a single line using Eureka framework


I'm currently using Eureka framework. I want my form to have a ImageView on the left side, and textfields or labels on the right side, similar as shown in the picture. Any ideas of what I need to do to accomplish this?

enter image description here


Solution

  • This is taken directly from the Eureka README

    // Custom Cell with value type: Bool
    // The cell is defined using a .xib, so we can set outlets :)
    public class CustomCell: Cell<Bool>, CellType {
        @IBOutlet weak var switchControl: UISwitch!
        @IBOutlet weak var label: UILabel!
    
        public override func setup() {
            super.setup()
            switchControl.addTarget(self, action: #selector(CustomCell.switchValueChanged), for: .valueChanged)
        }
    
        func switchValueChanged(){
            row.value = switchControl.on
            row.updateCell() // Re-draws the cell which calls 'update' bellow
        }
    
        public override func update() {
            super.update()
            backgroundColor = (row.value ?? false) ? .white : .black
        }
    }
    
    // The custom Row also has the cell: CustomCell and its correspond value
    public final class CustomRow: Row<CustomCell>, RowType {
        required public init(tag: String?) {
            super.init(tag: tag)
            // We set the cellProvider to load the .xib corresponding to our cell
            cellProvider = CellProvider<CustomCell>(nibName: "CustomCell")
        }
    }