Swift: gradient on a cell of a tableview

后端 未结 3 1806
轻奢々
轻奢々 2021-01-28 16:32

On tableView\'s cells, I\'m trying to define a gradient with the following Swift code:

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: N         


        
3条回答
  •  一生所求
    2021-01-28 16:50

    I had a similar problem, my mistake was inserting the new layer with gradient directly in the cell, try inserting the new layer to the backgroundView something like this

    let gradient = CAGradientLayer()
    // layer setup...
    cell.backgroundView = UIView()
    cell.backgroundView?.layer.insertSublayer(gradientLayer, atIndex: 0)
    

    Hope this helps.

提交回复
热议问题