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
Post a Comment