【问题标题】:SWIFT UITableViewCell with corner radius and shadow具有角半径和阴影的 SWIFT UITableViewCell
【发布时间】:2017-02-25 12:18:22
【问题描述】:

我一直在尝试创建一个带有圆角和阴影的自定义表格视图单元格,我设法创建了圆角,但阴影只显示在角落上,其他地方没有。

【问题讨论】:

    标签: ios swift swift3


    【解决方案1】:

    对于阴影和圆角,您可以使用以下代码:

     override func tableView(_ tableView: UICollectionView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    
         let cell = tableView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
         cell.layer.cornerRadius = 10
         let shadowPath2 = UIBezierPath(rect: cell.bounds)
         cell.layer.masksToBounds = false
         cell.layer.shadowColor = UIColor.black.cgColor
         cell.layer.shadowOffset = CGSize(width: CGFloat(1.0), height: CGFloat(3.0))
         cell.layer.shadowOpacity = 0.5
         cell.layer.shadowPath = shadowPath2.cgPath
         return cell
     }
    

    而且你可以调整数值,你会得到完美的阴影!

    希望对你有帮助!

    【讨论】:

      【解决方案2】:

      似乎 UITableviewCell 不支持投影。 Adding drop shadow to table view cell,请看这个。

      【讨论】:

        猜你喜欢
        • 2014-08-29
        • 1970-01-01
        • 2022-01-14
        • 2021-06-16
        • 1970-01-01
        • 2012-07-28
        • 1970-01-01
        • 2016-10-05
        • 1970-01-01
        相关资源
        最近更新 更多