gpt4 book ai didi

ios - 为 UIView 添加阴影和角,除了底部

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:02:00 25 4
gpt4 key购买 nike

我想在左上角和右上角添加圆角,并在其周围添加阴影(底部除外)。底部不应有阴影。我能够根据需要实现圆角。但不是影子。我需要一个同时实现两者的代码。在下图中查看诊断 View 。它的左上角和右上角是圆形的,周围有阴影。

enter image description here

最佳答案

试试这个代码。自定义方法。 swift 4.0

@IBOutlet weak var myView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
customCornerWithShadow(myView: myView, cornerRadius: 20)
}

func customCornerWithShadow(myView:UIView,cornerRadius:CGFloat) {

myView.layer.cornerRadius = cornerRadius
myView.clipsToBounds = false[enter image description here][1]
myView.layer.maskedCorners = CACornerMask(rawValue: CACornerMask.RawValue(UInt8(CACornerMask.layerMinXMinYCorner.rawValue) | UInt8(CACornerMask.layerMaxXMinYCorner.rawValue)))

myView.layer.shadowColor = #colorLiteral(red: 0.3098039329, green: 0.01568627544, blue: 0.1294117719, alpha: 1)
myView.layer.shadowOffset = CGSize(width:0, height:-1)

let shadowPath = UIBezierPath(roundedRect: myView.bounds, cornerRadius: cornerRadius)
myView.layer.shadowPath = shadowPath.cgPath
myView.layer.shadowOpacity = 1
}

关于ios - 为 UIView 添加阴影和角,除了底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51783502/

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