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

前端 未结 6 1497
盖世英雄少女心
盖世英雄少女心 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:17

    Here it is how we can add custom header in UITableView.

    func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
         let header: UITableViewHeaderFooterView = view as UITableViewHeaderFooterView
         let imageViewGame = UIImageView(frame: CGRectMake(5, 8, 40, 40));
         let image = UIImage(named: "Games.png");
         imageViewGame.image = image;
         header.contentView.addSubview(imageViewGame)
    }
    

提交回复
热议问题