微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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
 }

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

希望能帮助到你!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐