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!
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
})
})
Add this line
cell.societyImage.layer.masksToBounds = false
cell.societyImage.layer.shadowRadius = 2
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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.