带拐angular半径和阴影的SWIFT UITableViewCell

我一直在试图创build一个具有圆angular和阴影的自定义tableview单元格,我设法创build了圆angular,但阴影只显示在angular落,没有其他地方。

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

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 } 

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

希望能帮助到你!

在cellForRowAt indexPath中写下面的代码

  cell.contentView.layer.cornerRadius = 10 cell.contentView.layer.shadowColor = UIColor.blue.cgColor cell.contentView.layer.shadowRadius = 3 cell.contentView.layer.shadowOpacity = 1.0 cell.contentView.clipsToBounds = true 

看起来像UITableviewCell不支持阴影。 添加投影到表格视图单元格 ,请看看这个。