Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding drop shadow to table view cell [duplicate]

Tags:

swift

I am trying to add a drop shadow to a table cell but can't seem to get it to work.

I was able to successfully do it to a UIView in a scrollview using:

myStatsView.layer.shadowColor = UIColor.blackColor().CGColor
myStatsView.layer.shadowOffset = CGSizeMake(0,1)
myStatsView.layer.shadowRadius = 3
myStatsView.layer.shadowOpacity = 0.5

But I have updated my app for Swift 2 and decided to use table view instead of scrollview.

I tried adding the cell content view as an outlet but nothing seems to work.

Is it even possible to add shadows in between table cells? I don't want all cells to have a shadow, just some.

Thanks

like image 821
puks1978 Avatar asked Jun 10 '26 17:06

puks1978


1 Answers

I used different technique to add drop shadow to table cell. I add one UIView into the cell and add other controls like UILabel, UIImageView into that view and give the drop shadow to that view. Bellow is the code

self.viewBg!.layer.shadowOffset = CGSizeMake(0, 0)
self.viewBg!.layer.shadowColor = UIColor.blackColor().CGColor
self.viewBg!.layer.shadowRadius = 4
self.viewBg!.layer.shadowOpacity = 0.25
self.viewBg!.layer.masksToBounds = false;
self.viewBg!.clipsToBounds = false;

In above code viewBg is IBOutlet object.

like image 185
Bhavin_m Avatar answered Jun 12 '26 11:06

Bhavin_m



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!