繁体   English   中英

阴影不出现在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
})

任何帮助深表感谢!

关于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
    })   
})        

添加此行

cell.societyImage.layer.masksToBounds = false

cell.societyImage.layer.shadowRadius = 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;

暂无
暂无

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

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