Ios 在Swift 3.0的TableViewCell中设置视图的背景渐变色 我怎样才能达到这种渐变色呢?我尝试了很多东西,但是我没有达到这种渐变色。请帮帮我。谢谢你考虑我……p>

Ios 在Swift 3.0的TableViewCell中设置视图的背景渐变色 我怎样才能达到这种渐变色呢?我尝试了很多东西,但是我没有达到这种渐变色。请帮帮我。谢谢你考虑我……p>,ios,swift3,uicolor,Ios,Swift3,Uicolor,这是我的密码: func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { // create a new cell if needed or reuse an old one let cell:HomeTableViewCell = self.tableView.dequeueReusableCell(withIdenti

这是我的密码:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        // create a new cell if needed or reuse an old one
        let cell:HomeTableViewCell = self.tableView.dequeueReusableCell(withIdentifier: "Cell") as! HomeTableViewCell!
        //  let  image : UIImageView = cell.contentView.viewWithTag(2) as! UIImageView
        let gradient: CAGradientLayer = CAGradientLayer()
        gradient.frame = cell.bgView.bounds
        gradient.colors = [UIColor (colorLiteralRed: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 0.3), UIColor(red:0.51, green:0.53, blue:0.53, alpha:0.3)].map { $0.cgColor }
        gradient.locations = [0.0,1.0]
        cell.bgView?.layer.insertSublayer(gradient, at: 0)
        cell.layoutIfNeeded()
        cell.selectionStyle = UITableViewCellSelectionStyle.none
        return cell
    }

我认为实现这一点的最好方法是使用图层图像,您可以得到您想要的准确结果。您的bgView在图像视图之前吗?