ios - Change the sections header background color in UITableView using an array of headers -


i have array of headers use

let sectionheadertitlearray = ["test1","test2","test3] 

and showed using

func tableview[tableview: uitableview, titleforheaderinsection section: int) -> string? { return self.sectionheadertitlearray[section] string }  

now of works fine modify background color of headers more visible (darker color)

any idea if can in simple line or need use custom cell create this

thanks

update

  //number of sections , names table      func numberofsectionsintableview(tableview: uitableview) -> int {         return self.sectionheadertitlearray.count     }      func tableview(tableview: uitableview, titleforheaderinsection section: int) -> string? {         return self.sectionheadertitlearray[section] string     }     func tableview(tableview: uitableview, viewforheaderinsection section: int) -> uiview? {         return self.tableview.backgroundcolor = uicolor.lightgraycolor()     } 

instead of using the

func tableview(_ tableview: uitableview,titleforheaderinsection section: int) -> string? 

data source method, can use the

func tableview(_ tableview: uitableview, viewforheaderinsection section: int) -> uiview? 

delegate method , customize uiview returned wish.

for example set text of uilabel textlabel desired value , backgroundcolor desired uicolor.

func tableview(tableview: uitableview, viewforheaderinsection section: int) -> uiview? {     var returnedview = uiview(frame: cgrectmake(x, y, width, height)) //set these values necessary     returnedview.backgroundcolor = uicolor.lightgraycolor()      var label = uilabel(frame: cgrectmake(labelx, labely, labelwidth, labelheight))     label.text = self.sectionheadertitlearray[section]     returnedview.addsubview(label)      return returnedview } 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -