我一直在尝试创建一个带有圆角和投影的自定义tableview单元格,我设法创建了圆角,但阴影只显示在角落,其他地方没有显示。
对于阴影和圆角,您可以使用以下代码:
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
}
你可以调整数值,就会得到适合自己的完美阴影!
希望这有所帮助!