UITableView部分阴影

nik*_*nik 5 uitableview ios swift

如何在UITableViewController中实现tableView部分阴影.

Moh*_*shi 6

添加此方法以获取UITableView节的阴影此答案在Swift3中

func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    let shadowView = UIView()
    let gradient = CAGradientLayer()
    gradient.frame.size = CGSize(width: tableView.bounds.width, height: 15)

    let stopColor = UIColor.gray.cgColor    
    let startColor = UIColor.white.cgColor    

    gradient.colors = [stopColor, startColor]    
    gradient.locations = [0.0,0.8]

    shadowView.layer.addSublayer(gradient)    

    return shadowView
}
Run Code Online (Sandbox Code Playgroud)