ios - how to set a background image inside the UILabel inside a UITableViewCell -


i'm working on project in swift 3 i've set background image inside uilabel inside uitableviewcell. image consist of gradient color has fade away effect on edges. once set in code reason gradient color seems appear on 1 side of label(left side). perhaps not been adjusted fit in uilabel.how can set image fits label size properly, appreciate. code bellow.what missing

func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell {     switch indexpath.row {     case 0:         let cell =  tableview.dequeuereusablecell(withidentifier: "featuredcell", for: indexpath)         cell.bounds = cgrect(x: 0, y: 0, width: uiscreen.main.bounds.width, height: cell.bounds.height)         return cell      case (1...3):          let text = self.categoryselectiontitles[indexpath.row  - 2]         let cell = tableview.dequeuereusablecell(withidentifier: "audiocell",for: indexpath)         let labe = cell.viewwithtag(table_cell_tags.headerlabel) as! uilabel         labe.backgroundcolor = uicolor(patternimage: uiimage(named: "headerbar")!)          labe.bounds = cgrect(x: 0, y: 0, width: cell.frame.width, height: cell.frame.height)         utils.settablecelllabeltext(cell: cell, labeltag: 501, text: text)         return cell  } 

enter image description here

as per picture above right side of gradient not there.orginal picture bellow.

enter image description here

you use autolayout instead of frames this:

labe.translatesautoresizingmaskintoconstraints = false nslayoutconstraint.activate([   labe.leftanchor.constraint(equalto: cell.leftanchor),   labe.rightanchor.constraint(equalto: cell.rightanchor),   labe.topanchor.constraint(equalto: cell.topanchor),   labe.bottomanchor.constraint(equalto: cell.bottomanchor), ]) 

you'll want try make sure constraints added once.

or use masks:

labe.autoresizingmask = [.flexiblewidth, .flexibleheight] 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -