具有圆角半径和阴影的SWIFT UITableViewCell [英] SWIFT UITableViewCell with corner radius and shadow
本文介绍了具有圆角半径和阴影的SWIFT UITableViewCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试创建一个带有圆角和阴影的自定义tableview单元格,我设法创建了圆角但阴影只显示在角落而没有其他地方。
I've been trying to create a custom tableview cell with rounded corners and drop shadow, I managed to create the rounded corners but the shadow is showing only on the corners and no where else.
推荐答案
对于阴影和圆角,您可以使用以下代码:
For both the shadow and the rounded corners, you can use this code:
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
}
你可以调整价值,你就会得到完美的阴影!
And you can adjust the values and you'll get the perfect shadow for you!
希望它有所帮助!
这篇关于具有圆角半径和阴影的SWIFT UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文