如何向 selectedBackgroundView UITableViewCell Swift 添加阴影
Posted
技术标签:
【中文标题】如何向 selectedBackgroundView UITableViewCell Swift 添加阴影【英文标题】:How to add shadow to selectedBackgroundView UITableViewCell Swift 【发布时间】:2016-07-15 08:44:06 【问题描述】:我正在尝试为UITableViewCell.selectedBackgroundView
添加阴影效果,但这没有显示。当我设置背景颜色时,我可以看到它被添加了,所以我在设置阴影时做错了。这是我在cellForRowAtIndexPath
下面的代码。
///Setting selected UIView
let selectedView = UIView(frame: cell.frame)
selectedView.layer.shadowOpacity = 0.35
selectedView.layer.shadowOffset = CGSizeMake(0, 2)
selectedView.layer.shadowRadius = 5
selectedView.layer.shadowColor = UIColor.blackColor().CGColor
selectedView.clipsToBounds = false
cell.selectedBackgroundView = selectedView
cell.contentView.clipsToBounds = false
cell.clipsToBounds = false
【问题讨论】:
试过把它放在 didselectrowAtIndexPath 中吗? 我认为阴影被下一个单元格隐藏了...... @Happiehappie 现在尝试了,但仍然没有成功 @Lumialxk 如何测试他的? 您可以添加具有清晰颜色的单元格来进行测试。 【参考方案1】:仔细检查您的选择风格。确保它是 .Default 而不是 .None
cell.selectionStyle = .Default
我测试了你的代码,它运行良好
另外,可以忽略我对您的开篇文章的评论,我这样做是 cellForRowAtIndexPath 并且它按预期工作
【讨论】:
以上是关于如何向 selectedBackgroundView UITableViewCell Swift 添加阴影的主要内容,如果未能解决你的问题,请参考以下文章