gpt4 book ai didi

ios - 圆形 View 上的阴影不均匀

转载 作者:行者123 更新时间:2023-11-28 13:55:10 24 4
gpt4 key购买 nike

我有一个 collectionview 单元格,我有一个容器 UIView() ,它与 super View 有一定距离。 containerview 是圆形的,我正在尝试对其应用投影。我很好地实现了这一点,直到在某些单元格上它打破了阴影层并产生了不均匀的阴影效果。以下是当前结果: enter image description here

以下是我的代码:

extension UIView() {
func dropShadow(color: UIColor, opacity: Float = 0.5, offSet: CGSize, radius: CGFloat = 1, scale: Bool = true) {
self.layer.masksToBounds = false
self.layer.shadowColor = color.cgColor
self.layer.shadowOpacity = opacity
self.layer.shadowOffset = offSet
self.layer.shadowRadius = radius

self.layer.shadowPath = UIBezierPath(roundedRect: self.bounds, cornerRadius: radius).cgPath
self.layer.shouldRasterize = true
self.layer.rasterizationScale = scale ? UIScreen.main.scale : 1
}
}

下面是UICollectionViewCell.swift

override func layoutSubviews() {
super.layoutSubviews()
containerView.dropShadow(color: .lightGray, opacity: 6, offSet: CGSize(width: 0, height: 0), radius: 6, scale: true)
}

非常感谢任何帮助。

最佳答案

我在 collectionview 单元格内的 View 中使用了阴影。请看下面的链接

View Sample

这是在 cellforItem 里面

myCell.imgIcon.backgroundColor = UIColor.white
myCell.imgIcon.layer.shadowColor = UIColor.lightGray.cgColor
myCell.imgIcon.layer.shadowOpacity = 0.5
myCell.imgIcon.layer.shadowOffset = CGSize(width: 0, height: 0)
myCell.imgIcon.layer.shadowRadius = 5

关于ios - 圆形 View 上的阴影不均匀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53975098/

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