How can we add image in UITableView section header using swift?

前端 未结 6 1495
盖世英雄少女心
盖世英雄少女心 2021-02-04 10:54

In my willDisplayHeaderView I have changed color of section header But I want to add an image before section title. Any help? My code for willDisplayHeaderView is



        
6条回答
  •  悲&欢浪女
    2021-02-04 11:26

    For Swift 3

      override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
        let header = view as! UITableViewHeaderFooterView
        header.textLabel?.textColor = UIColor.white
        let headerImage = UIImage(named: "headerBanner.jpg")
        let headerImageView = UIImageView(image: headerImage)
        header.backgroundView = headerImageView
    }
    

提交回复
热议问题