tableViewController中的渐变没有填满整个背景

时间:2017-12-19 14:29:12

标签: ios swift uitableview

我在ViewHelper类中设置渐变的方法:

class func BackGroundColorTableView(vc: UITableViewController, view:UIView) {

    let startColor = UIColor(red:0.84, green:0.82, blue:0.80, alpha:1.0)
    let endColor = UIColor(red:0.19, green:0.26, blue:0.32, alpha:1.0)
    let gradientBackgroundColors = [startColor.cgColor, endColor.cgColor]
    let gradientLocations = [0.0,1.0]
    let gradientLayer = CAGradientLayer()

   gradientLayer.colors = gradientBackgroundColors
    gradientLayer.locations = gradientLocations as [NSNumber]
    gradientLayer.frame = vc.tableView.bounds

   let backgroundView = UIView(frame: vc.tableView.bounds)
    backgroundView.layer.insertSublayer(gradientLayer, at: 0)
    vc.tableView.backgroundView = backgroundView
}

然后我调用我的函数;

 ViewHelper.BackGroundColorTableView(vc: self, view: self.view)
 tableView.separatorStyle = UITableViewCellSeparatorStyle.none

和代表;

override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    cell.backgroundColor = UIColor.clear
}

问题是,底部有一个间隙,没有显示渐变:见图 image

如何解决?

0 个答案:

没有答案
相关问题