简体   繁体   English

UITableView中的阴影过多

[英]Excessive drop shadow in UITableView

Here is a screenshot: 这是一个截图:

在此输入图像描述

If you look at the top cell, there is an excessive drop shadow while the one at the bottom has the intended drop shadow effect. 如果您查看顶部单元格,则会出现过多的阴影,而底部的阴影具有预期的投影效果。 The excessive ones disappears and becomes normal after scrolling it out of screen then coming back to it. 过多的那些在从屏幕滚出然后回到它之后消失并变得正常。 I can not figure out what is going on with this. 我无法弄清楚这是怎么回事。

Here is my drop shadow code in the tableview cell class : 这是tableview单元类中的阴影代码:

override func layoutSubviews() {
    super.layoutSubviews()
    let shadowPath = UIBezierPath(rect: containerView.bounds)
    containerView.layer.masksToBounds = false
    containerView.layer.shadowColor = UIColor.black.cgColor
    containerView.layer.shadowOffset = CGSize(width: 0, height: 0.1)
    containerView.layer.shadowOpacity = 0.2
    containerView.layer.shadowPath = shadowPath.cgPath
  }

Please help and Thank you! 请帮忙,谢谢!

I figured this out. 我想通了。 basically, I was using containerView.bounds for shadow path but the layer was drawn way too big because the cell started off big then shrunk based on device. 基本上,我使用了containerView.bounds作为阴影路径,但是绘制的图层太大了,因为单元格开始大而基于设备缩小。 The solution is to use constants. 解决方案是使用常量。 Anticipate the height and width and use CGRect. 预测高度和宽度并使用CGRect。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM