SWIFT UITableViewCell with corner radius and shadow

后端 未结 2 1074
梦如初夏
梦如初夏 2021-02-06 11:35

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 a

相关标签:
2条回答
  • 2021-02-06 11:43

    seems like UITableviewCell doesnt support drop shadows. Adding drop shadow to table view cell, please take a look at this.

    0 讨论(0)
  • 2021-02-06 11:56

    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!

    Hope it helps!

    0 讨论(0)
提交回复
热议问题