gpt4 book ai didi

ios - 在 UIView 顶部添加阴影

转载 作者:可可西里 更新时间:2023-11-01 03:05:15 24 4
gpt4 key购买 nike

如何在我的 UIView 顶部添加阴影我已经尝试了以下但没有成功...

childView.layer.cornerRadius = 5;
childView.layer.masksToBounds = YES;
childView.layer.shadowOffset = CGSizeMake(-15, 20);
childView.layer.shadowRadius = 5;
childView.layer.shadowOpacity = 0.5;

最佳答案

Swift 3 扩展:

这包括我正在处理的应用程序的默认值,但您可以更改它们以匹配您想要的应用程序样式。

enum VerticalLocation: String {
case bottom
case top
}

extension UIView {
func addShadow(location: VerticalLocation, color: UIColor = .black, opacity: Float = 0.5, radius: CGFloat = 5.0) {
switch location {
case .bottom:
addShadow(offset: CGSize(width: 0, height: 10), color: color, opacity: opacity, radius: radius)
case .top:
addShadow(offset: CGSize(width: 0, height: -10), color: color, opacity: opacity, radius: radius)
}
}

func addShadow(offset: CGSize, color: UIColor = .black, opacity: Float = 0.5, radius: CGFloat = 5.0) {
self.layer.masksToBounds = false
self.layer.shadowColor = color.cgColor
self.layer.shadowOffset = offset
self.layer.shadowOpacity = opacity
self.layer.shadowRadius = radius
}
}

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

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