简体   繁体   English

阴影不出现在UIImageView(Swift)下

[英]Shadow not appearing under UIImageView (Swift)

I have written the following code to download and display an image in the cells of a tableView. 我编写了以下代码来下载并在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. 关于maskToBounds :如果你把它设置为true那么你就不会看到阴影,因为它会maskToBounds子层,而其他地方为false,它允许扩展图层。

...    
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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM