【问题标题】:How to add shadow to selectedBackgroundView UITableViewCell Swift如何向 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 如何测试他的?
  • 您可以添加具有清晰颜色的单元格来进行测试。

标签: ios arrays uitableview uiview


【解决方案1】:

仔细检查您的选择风格。确保它是 .Default 而不是 .None

cell.selectionStyle = .Default

我测试了你的代码,它运行良好

另外,可以忽略我对您的开篇文章的评论,我这样做是 cellForRowAtIndexPath 并且它按预期工作

【讨论】:

    猜你喜欢
    • 2013-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    • 1970-01-01
    • 1970-01-01
    • 2012-02-19
    • 2015-11-03
    相关资源
    最近更新 更多