gpt4 book ai didi

ios - 如何在ios Swift中的UIView中设置左右和底部的阴影?

转载 作者:行者123 更新时间:2023-11-30 12:06:41 24 4
gpt4 key购买 nike

我希望 View 中的左侧、右侧和底部有阴影。但 Swift 3 阴影偏移仅提供高度或宽度。我找到了类似的答案,请参阅下面的链接,它显示阴影左上右阴影。我想要左、右、下。

  1. 查看链接little similar answer

最佳答案

这与提供的链接几乎相同的任务,只需更改 BezierPath

let block1 = UIView(frame: CGRect.init(x: 50, y: 50, width: 300, height: 300))
block1.backgroundColor = UIColor.red

block1.layer.masksToBounds = false
block1.layer.shadowOffset = CGSize(width: 0.0, height: 0.0)
block1.layer.shadowRadius = 5.0
block1.layer.shadowOpacity = 0.7

let path = UIBezierPath()
path.move(to: CGPoint(x: 0.0, y: 0.0))
// Move to center between two top points instead of bottom
path.addLine(to: CGPoint(x: block1.frame.size.width/2.0, y: block1.frame.size.height/2.0))
path.addLine(to: CGPoint(x: block1.frame.size.width, y: 0.0))
path.addLine(to: CGPoint(x: block1.frame.size.width, y: block1.frame.size.height))
path.addLine(to: CGPoint(x: 0.0, y: block1.frame.size.height))
path.close()
block1.layer.shadowPath = path.cgPath

关于ios - 如何在ios Swift中的UIView中设置左右和底部的阴影?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46602096/

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