gpt4 book ai didi

ios - iOS 无法设置 UIView 的底部阴影?

转载 作者:行者123 更新时间:2023-11-30 12:29:36 25 4
gpt4 key购买 nike

我想设置 UIView 的底部阴影。我还设置圆角半径。如果我将 ma​​skToBounds 设置为 true 那么我无法设置UIView请告诉我如何设置UIView的角半径和阴影。

 func addShadwToView(){
self.viewContainer.layer.masksToBounds = true;
self.viewContainer.layer.shadowRadius = 15;
self.viewContainer.layer.shadowOffset = CGSize(width: 0, height: 20)
self.viewContainer.layer.shadowOpacity = 0.5;
self.viewContainer.layer.cornerRadius = 5
self.viewContainer.layer.borderColor = UIColor.lightGray.cgColor
self.viewContainer.layer.borderWidth = 0.5
}

最佳答案

如果您同时想要角半径和投影,请不要打开 -masksToBounds,而是设置角半径并使用圆角矩形设置阴影的贝塞尔曲线路径。保持两者的半径相同:尝试一下:

func addShadwToView(){
var borderLine = CAShapeLayer()
borderLine.path = UIBezierPath(roundedRect: frame2, byRoundingCorners: [.allCorners], cornerRadii: CGSize(width: 30, height: 0)).cgPath
borderLine.shadowColor = UIColor.white.cgColor
borderLine.shadowOffset = CGSize(width: 0, height: 1)
borderLine.shadowOpacity = 0.3
borderLine.shadowRadius = 10

self.viewContainer.layer.masksToBounds = true;
self.viewContainer.layer.cornerRadius = 5
self.viewContainer.layer.borderColor = UIColor.lightGray.cgColor
self.viewContainer.layer.borderWidth = 0.5
self.viewContainer.layer.addSublayer(borderLine)
}

关于ios - iOS 无法设置 UIView 的底部阴影?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43734012/

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