gpt4 book ai didi

swift - Tableview 单元格阴影无法正确呈现 Swift

转载 作者:搜寻专家 更新时间:2023-10-31 22:45:55 26 4
gpt4 key购买 nike

我已经能够使用以下代码将阴影添加到我的 tableview 单元格的底部,但是它似乎在之后消失了我向下滚动。

cell.layer.shadowColor = UIColor.blackColor().CGColor
cell.layer.shadowOffset = CGSizeMake(0,2)
cell.layer.shadowRadius = 3
cell.layer.shadowOpacity = 0.5
let shadowFrame: CGRect = cell.layer.bounds
let shadowPath: CGPathRef = UIBezierPath(rect: shadowFrame).CGPath
cell.layer.shadowPath = shadowPath
cell.layer.masksToBounds = false

enter image description here

最佳答案

问题与阴影偏移有关,我已设法通过以下方式纠正:

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {

cell.layer.backgroundColor = UIColor.clearColor().CGColor
cell.layer.shadowColor = UIColor.blackColor().CGColor
cell.layer.shadowOffset = CGSizeZero
cell.layer.shadowRadius = 4
cell.layer.shadowOpacity = 0.5
cell.layer.shadowPath = UIBezierPath(rect: cell.bounds).CGPath
cell.layer.masksToBounds = false

}

关于swift - Tableview 单元格阴影无法正确呈现 Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38174949/

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