阴影未出现在 UIImageView 下 (Swift)

Shadow not appearing under UIImageView (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
})

非常感谢任何帮助!

添加这一行

cell.societyImage.layer.masksToBounds = false

cell.societyImage.layer.shadowRadius = 2

关于maskToBounds:如果你把它设置为 true 那么你将不会看到阴影,因为它会剪裁子层,否则它允许扩展层。

...    
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
    })   
})        

您应该设置以下参数,

 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;