Reputation: 399
I have written the following code to download and display an image in the cells of a tableView. However, the drop shadow isn't appearing at all and I can't figure out what is wrong.
cell.societyImage.setIndicatorStyle(UIActivityIndicatorViewStyle.White)
cell.societyImage.setShowActivityIndicatorView(true)
cell.societyImage.sd_setImageWithURL(NSURL(string: pictureURLs[objectIds[indexPath.row]]!),completed: { (image, error, cache, url) in
cell.societyImage.layer.shadowColor = UIColor(white: 0.7, alpha: 0.7).CGColor
cell.societyImage.layer.shadowOffset = CGSizeMake(3, 3)
cell.societyImage.layer.shadowOpacity = 0.4
cell.societyImage.layer.masksToBounds = true
})
Any help is much appreciated!
Upvotes: 3
Views: 7235
Reputation: 2640
Add this line
cell.societyImage.layer.masksToBounds = false
cell.societyImage.layer.shadowRadius = 2
Upvotes: 2
Reputation: 27428
You should set following parameters,
cell.societyImage.layer.shadowOffset = CGSizeMake(0, 0)
cell.societyImage.layer.shadowColor = UIColor.blackColor().CGColor
cell.societyImage.layer.shadowRadius = 4
cell.societyImage.layer.shadowOpacity = 0.25
cell.societyImage.layer.masksToBounds = false;
cell.societyImage.clipsToBounds = false;
Upvotes: 0
Reputation: 35392
About maskToBounds
: if you put it true then you won't see shadow as it clips sublayer where else in false it allow to extent layer.
...
cell.societyImage.sd_setImageWithURL(NSURL(string: pictureURLs[objectIds[indexPath.row]]!),completed: { (image, error, cache, url) in
dispatch_async(dispatch_get_main_queue()) {
let shadowPath = UIBezierPath(rect: cell.societyImage.bounds).CGPath
cell.societyImage.layer.shadowColor = UIColor(white: 0.7, alpha: 0.7).CGColor
cell.societyImage.layer.shadowOffset = CGSizeMake(3, 3)
cell.societyImage.layer.shadowOpacity = 0.4
cell.societyImage.layer.masksToBounds = false
cell.societyImage.layer.shadowPath = shadowPath.CGPath
cell.societyImage.layer.radius = 2
})
})
Upvotes: 6