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

前端 未结 6 1509
盖世英雄少女心
盖世英雄少女心 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条回答
  •  旧时难觅i
    2021-02-04 11:16

    I use this method below in my proj.

    override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? 
    {
        let uilbl = UILabel()
        //uilbl.numberOfLines = 0
        //uilbl.lineBreakMode = NSLineBreakMode.ByWordWrapping
        //uilbl.text = "blablabla"
        uilbl.sizeToFit()
        uilbl.backgroundColor =  UIColor(patternImage: UIImage(named: "yr-img-name")!)
    
        return uilbl
    }
    

提交回复
热议问题