作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望图像显示为带有阴影的圆圈。执行以下操作不起作用,因为阴影可能被剪切切断......
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/
这段代码是 -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-radiu
我希望图像显示为带有阴影的圆圈。执行以下操作不起作用,因为阴影可能被剪切切断...... let layer = myImageView.layer // cut circle layer.borde
我是一名优秀的程序员,十分优秀!