我提出這兩個例子夫特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
}
這是結果:
![enter image description here](https://i.stack.imgur.com/fNr8o.png)
影弧:
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
}
這是結果:
![enter image description here](https://i.stack.imgur.com/bhGAI.png)
來源
2016-10-14 14:29:48
Rob
您試過了哪些代碼? – Rob
我編輯了這個問題。 – Slavcho
您可以使用添加圖像視圖(以及陰影圖像)來隱藏離開最後一個單元格的所有單元格的圖像視圖。這將解決您的問題。 –