gpt4 book ai didi

ios - 在蒙版 UIView 周围添加阴影

转载 作者:搜寻专家 更新时间:2023-11-01 06:10:50 25 4
gpt4 key购买 nike

我正在尝试创建一个带有提示的弹出窗口。以下是此代码

tipView.frame = CGRect(x: at.x - size.width, y: at.y, width: size.width, height: size.height)
let imgView = UIImageView.init(frame: CGRect(x: 0, y: 0, width: tipView.frame.width, height: tipView.frame.height))
imgView.image = #imageLiteral(resourceName: "popup.png")
tipView.mask = imgView

我用弹出窗口形状的图像遮盖了 UIView。

现在我想在 UIView 的所有 4 个边上添加阴影。我尝试了所有的方法。但是影子不可见

enter image description here

最佳答案

添加以下代码为 tipView 添加阴影和圆角半径。清除 backgroundColor 并使 tipView 的 clipsToBounds = false

    let shapeLayer = CAShapeLayer()
shapeLayer.path = UIBezierPath(roundedRect: tipView.bounds, byRoundingCorners: [.topLeft, .bottomLeft, .bottomRight], cornerRadii: CGSize(width: 20, height: 20)).cgPath
shapeLayer.fillColor = UIColor.darkGray.cgColor
shapeLayer.masksToBounds = false

shapeLayer.shadowColor = UIColor.darkGray.cgColor
shapeLayer.shadowPath = shapeLayer.path
shapeLayer.shadowOffset = CGSize(width: 0, height: 2)
shapeLayer.shadowOpacity = 0.5
shapeLayer.shadowRadius = 2.0

tipView.layer.insertSublayer(shapeLayer, at: 0)

关于ios - 在蒙版 UIView 周围添加阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57864684/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com