我提出这两个例子夫特3。首先它是一个经典的影子,我用CAGradientLayer。第二个是阴影弧,我用UIBezierPath,CAShapeLayer和CAGradientLayer。
经典影:
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let shadowView = UIView()
let gradient = CAGradientLayer()
gradient.frame.size = CGSize(width: myTab.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
}
这是结果:
影弧:
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let shadowView = UIView()
let path = UIBezierPath()
path.move(to: CGPoint.zero)
path.addLine(to: (CGPoint(x: (myTab.bounds.maxX), y: 0.0)))
path.addLine(to: (CGPoint(x: (myTab.bounds.maxX), y: 15)))
path.addCurve(to: (CGPoint(x: 0.0, y: 15)), controlPoint1: (CGPoint(x: (myTab.bounds.midX), y: -10)), controlPoint2: (CGPoint(x: 0.0, y: 15)))
path.addLine(to: CGPoint.zero)
let shape = CAShapeLayer()
shape.path = path.cgPath
let gradient = CAGradientLayer()
gradient.frame.size = CGSize(width: myTab.bounds.width, height: 15)
let stopColor = UIColor.gray.cgColor
let startColor = UIColor.white.cgColor
gradient.colors = [stopColor,startColor]
gradient.locations = [0.0,0.9]
gradient.mask = shape
shadowView.backgroundColor = UIColor.white
shadowView.layer.addSublayer(gradient)
return shadowView
}
这是结果:
来源
2016-10-14 14:29:48
Rob
您试过了哪些代码? – Rob
我编辑了这个问题。 – Slavcho
您可以使用添加图像视图(以及阴影图像)来隐藏离开最后一个单元格的所有单元格的图像视图。这将解决您的问题。 –