阴影不出现在UIImageView(Swift)下

Swa*_*wal 2 shadow uiimageview ios swift

我编写了以下代码来下载并在tableView的单元格中显示图像.然而,投影根本没有出现,我无法弄清楚出了什么问题.

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
})
Run Code Online (Sandbox Code Playgroud)

任何帮助深表感谢!

Ale*_*ano 5

关于maskToBounds:如果你把它设置为真,那么你就不会看到阴影,因为它会将子图层剪切到其他地方,因为它允许扩展图层.

...    
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
    })   
})        
Run Code Online (Sandbox Code Playgroud)