Ios 如何在UIView的填充之外创建阴影?
我有一个半透明填充的单元格。由于填充是半透明的,我可以看到填充后面的阴影。如何将阴影隐藏在单元格填充下Ios 如何在UIView的填充之外创建阴影?,ios,swift,shadow,Ios,Swift,Shadow,我有一个半透明填充的单元格。由于填充是半透明的,我可以看到填充后面的阴影。如何将阴影隐藏在单元格填充下 self.layer.cornerRadius = 6 self.layer.masksToBounds = false self.layer.shadowOpacity = 0.8 self.layer.shadowColor = UIColor.black.withAlphaComponent(0.6).cgColor self.layer.shadowRadius = 2 self.
self.layer.cornerRadius = 6
self.layer.masksToBounds = false
self.layer.shadowOpacity = 0.8
self.layer.shadowColor = UIColor.black.withAlphaComponent(0.6).cgColor
self.layer.shadowRadius = 2
self.layer.shadowOffset = CGSize(width: 5, height: 5)
这就是我所拥有的:具有透明视图的所需结果:
这可能会有所帮助。我们需要做的就是改变阴影路径
cell.layer.cornerRadius = 6
cell.layer.masksToBounds = false
cell.layer.shadowOpacity = 0.8
cell.layer.shadowColor = UIColor.black.withAlphaComponent(0.6).cgColor
cell.layer.shadowRadius = 2
cell.layer.shadowOffset = CGSize(width: 5, height: 5)
let rect = CGRect(x: cell.frame.origin.x, y: cell.frame.origin.y + cell.frame.size.height, width: cell.frame.size.width, height: 3)
cell.layer.shadowPath = CGPath(roundedRect: rect, cornerWidth: 1, cornerHeight: 1, transform: nil)
据我所知,你需要这种观点: 您可以尝试以下方法:
let viewShadow = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
viewShadow.center = self.view.center
viewShadow.layer.cornerRadius = 10.0
viewShadow.layer.borderColor = UIColor.black.cgColor
viewShadow.layer.borderWidth = 0.5
viewShadow.backgroundColor = UIColor.white.withAlphaComponent(0.4)
viewShadow.layer.shadowColor = UIColor.lightGray.cgColor
viewShadow.layer.shadowOpacity = 1
viewShadow.layer.shadowOffset = CGSize(width: 20.0, height: 20.0)
viewShadow.layer.shadowRadius = 5
self.view.addSubview(viewShadow)
输出
希望这有帮助。你能发布一个截图或其他什么吗?我不确定1)正在发生什么,2)你希望发生什么。我在回答中添加了屏幕截图。这是当前结果还是期望的结果?这是当前结果,我们可以看到细胞框架内的阴影。但我只希望在cellWell后面看到它。我想你必须在半透明和阴影之间做出决定。视图必须为alpha=0.6,如果在你的变体中,我实现了透明,阴影在cellWell下面可见。我刚才建议你,我认为这会对你有所帮助。如果它对你有用,或者它帮助你投票或批准@SergeyHleb,因此它赞扬了我们。在我的情况下,它没有帮助。请你解释一下你到底想要什么。我只想看到填充后面的阴影,而不是半透明单元格下面的阴影