gpt4 book ai didi

swift - 层: Set corder radius then add a shadow

转载 作者:行者123 更新时间:2023-11-30 14:00:46 24 4
gpt4 key购买 nike

我希望图像显示为带有阴影的圆圈。执行以下操作不起作用,因为阴影可能被剪切切断......

let layer = myImageView.layer
// cut circle
layer.borderWidth = 1
layer.masksToBounds = false
layer.borderColor = UIColor.whiteColor().CGColor
layer.cornerRadius = myImageView.frame.height/2
myImageView.clipsToBounds = true
// add shadow
layer.shadowColor = UIColor.blackColor().CGColor
layer.shadowOffset = CGSize(width: 0, height: 10)
layer.shadowOpacity = 0.4
layer.shadowRadius = 5

最佳答案

我也遇到了同样的问题...

我通过在按钮顶部放置一个图像(在我的例子中是一个按钮而不是图像)来解决这个问题,就像一个阴影。

button.sizeToFit()
shadow.layer.cornerRadius = 6
shadow.backgroundColor = UIColor.whiteColor()
shadow.layer.shadowOpacity = 0.8
shadow.layer.shadowRadius = 6
shadow.layer.shadowOffset = CGSizeMake(0, 2)
button.layer.cornerRadius = 6
button.clipsToBounds = true

shadow 当然是将成为阴影的 imageView。

按钮在您的情况下将是您的图像。

关于swift - 层: Set corder radius then add a shadow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33024459/

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