我要这个
我的代码
let shadowPath = UIBezierPath(rect: shadowView.bounds).cgPath
shadowView.layer.shadowColor = UIColor.grey.cgColor
shadowView.layer.shadowOffset = CGSize(width: 0, height: 1)
shadowView.layer.shadowOpacity = 0.5
shadowView.layer.masksToBounds = false
shadowView.layer.shadowPath = shadowPath
shadowView.layer.shadowRadius = 5
我想在我的 UIVIew 中实现完全相同的阴影。当我用上面的代码运行我的应用程序时,它分布在 4 个面。注意:阴影两边较细,中间较粗。
最佳答案
尝试创建自定义路径:
let shadowPath = UIBezierPath()
shadowPath.move(to: CGPoint(x: someView.bounds.origin.x, y: someView.frame.size.height))
shadowPath.addLine(to: CGPoint(x: someView.bounds.width / 2, y: someView.bounds.height + 7.0))
shadowPath.addLine(to: CGPoint(x: someView.bounds.width, y: someView.bounds.height))
shadowPath.close()
shadowView.layer.shadowColor = UIColor.darkGray.cgColor
shadowView.layer.shadowOpacity = 1
shadowView.layer.masksToBounds = false
shadowView.layer.shadowPath = shadowPath.cgPath
shadowView.layer.shadowRadius = 5
这会给出类似的结果,请尝试自定义点位置和其他值以满足您的需要。
关于ios - 如何在 Swift 3 中为 UIView 提供底部阴影?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46315286/