user6679849
user6679849

Reputation: 71

SWIFT UITableViewCell with corner radius and shadow

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.

Upvotes: 7

Views: 15046

Answers (2)

Manoj Karki
Manoj Karki

Reputation: 270

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

Upvotes: 0

Mr. Xcoder
Mr. Xcoder

Reputation: 4795

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!

Upvotes: 13

Related Questions