ios – 带角半径和阴影的SWIFT UITableViewCell

我一直在尝试创建一个带有圆角和阴影的自定义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
 }

你可以调整价值,你将获得完美的阴影!

希望能帮助到你!

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...