Eureka: Any way to change the Section Header/Footer Background color without Custom Views?

Created on 6 Jul 2017  路  3Comments  路  Source: xmartlabs/Eureka

Is there a way to change the Section Header and footer background color without using any custom Views or xib?

  • Environment: Eureka, Xcode 8 and iOS version 10.3.
section header footer question

Most helpful comment

I don't know if there is a Eureka-specific/approved method, but the willDisplayHeaderView delegate does the trick for me:

    func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
        if let header = view as? UITableViewHeaderFooterView {
            header.backgroundView?.backgroundColor = UIColor.green
            header.textLabel?.textColor = UIColor.yellow
        }
    }

works for headers that are shown like this:

        var section = Section()
        section.header = HeaderFooterView(stringLiteral: "Ugly Header")
        form +++ section

All 3 comments

I don't know if there is a Eureka-specific/approved method, but the willDisplayHeaderView delegate does the trick for me:

    func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
        if let header = view as? UITableViewHeaderFooterView {
            header.backgroundView?.backgroundColor = UIColor.green
            header.textLabel?.textColor = UIColor.yellow
        }
    }

works for headers that are shown like this:

        var section = Section()
        section.header = HeaderFooterView(stringLiteral: "Ugly Header")
        form +++ section

FWIW, there is a Eureka way using onSetupView but as of release 3.1 I think it may be broken.

            var hfv = HeaderFooterView(stringLiteral: "Ugly Header")
            hfv.onSetupView = { view, _ in
                if let header = view as? UITableViewHeaderFooterView {
                     header.backgroundView?.backgroundColor = .yellow
                }
            }
            section.header = hfv

I don't know if there is a Eureka-specific/approved method, but the willDisplayHeaderView delegate does the trick for me:

    func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
        if let header = view as? UITableViewHeaderFooterView {
            header.backgroundView?.backgroundColor = UIColor.green
            header.textLabel?.textColor = UIColor.yellow
        }
    }

works for headers that are shown like this:

        var section = Section()
        section.header = HeaderFooterView(stringLiteral: "Ugly Header")
        form +++ section

Hi @eliburke I tried this method and the background color doesn't work, but the text color works. Are u able to make it work? I'm using Eureka 4.3.0

Was this page helpful?
0 / 5 - 0 ratings