-2

I am populating the collection view cells. But only for a single cell, I want a different background color with shadow to the cell. So far I am able to give background color but can't find any idea, how to give shadow. Any suggestions...

cell.backgroundColor = UIColor.init(alpha: 1, red: 255, green: 221, blue: 126)

let view = UIView()
view.frame = CGRect(x: 20, y: cell.frame.origin.y + 62, width: cell.frame.size.width, height: 50)
view.layer.shadowColor = UIColor.black.cgColor
view.layer.shadowOffset = CGSize(width: 3, height: 3)
view.layer.shadowOpacity = 0.9
view.backgroundColor = UIColor.clear
self.addSubview(view)

return cell

This is what I did

This is what I did

This is what I want

This is what I want

Andrew
  • 26,706
  • 9
  • 85
  • 101
vinuChan
  • 9
  • 2
  • Check this, [https://stackoverflow.com/questions/37645408/uitableviewcell-rounded-corners-and-shadow] – Austin Michael Feb 13 '20 at 10:04
  • Add your code and show what you have tried. – Daljeet Feb 13 '20 at 10:06
  • Hey there! As you seem to be new here, I'll list a couple things that people usually do before asking a question: 1) Get an idea, try it out and ask what's wrong with it, if it doesn't work. 2) If you don't have an idea, search if there is a same/similar question that has a solution that might help, and proceed to point 1 :) – Lokesh SN Feb 13 '20 at 10:29
  • Also try your best to include whatever you've tried so far as a part of the question, so that this doesn't seem to people like some "Write code for me" question – Lokesh SN Feb 13 '20 at 10:32

1 Answers1

-1

I can give you a way of doing it.

Give your cell a clear color

Add a child view in it make sure to give proper constrains (make sure to keep the child view inside the cell).

Add all labels or any other views inside the new child view

Give shadows and background color to the child view. (make sure to toggle the color when needed just as selected color)

I am sure this will definitely look the image you have sown

shinoy
  • 146
  • 1
  • 8