Ios 如何仅在UITableView部分的底部添加阴影?
我有一个分段的Ios 如何仅在UITableView部分的底部添加阴影?,ios,iphone,swift,uitableview,Ios,Iphone,Swift,Uitableview,我有一个分段的UITableView,标题高度为10,背景颜色为clearColor,只是为了显示更为分离的部分。现在我只需要在每个部分的底部添加一个阴影。我曾尝试将阴影添加到viewForHeaderInSection方法中,但结果非常糟糕。实现这一点有什么建议吗 func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { let shadowView = UIV
UITableView
,标题高度为10,背景颜色为clearColor
,只是为了显示更为分离的部分。现在我只需要在每个部分的底部添加一个阴影。我曾尝试将阴影添加到viewForHeaderInSection
方法中,但结果非常糟糕。实现这一点有什么建议吗
func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let shadowView = UIView()
shadowView.layer.shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5).CGColor
shadowView.layer.shadowOffset = CGSizeMake(0.0, 2.0)
shadowView.layer.shadowOpacity = 1.0
shadowView.layer.shadowRadius = 0.0
shadowView.layer.masksToBounds = false
return shadowView
}
func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 2
}
我举了这两个例子swift3。首先是一个经典的阴影,我用了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
}
结果是:
我举了这两个例子Swift 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
}
结果是:
您尝试了哪些代码?我已编辑了问题。您可以使用“添加图像视图”(连同阴影图像)隐藏离开最后一个单元格的所有单元格的图像视图。这将解决您的问题。您尝试了哪些代码?我已编辑了该问题。您可以使用“添加图像视图”(连同阴影图像)隐藏离开最后一个单元格的所有单元格的图像视图。这会解决你的问题。这就是我需要的。第一种方法是好的。如果你实现了问题中的一个,它将添加页脚视图,然后在它下面会出现阴影。这就是我需要的。第一种方法是好的。如果您实现问题中的一个,它将添加页脚视图,然后阴影将出现在它下面。