我编写了以下代码来下载并在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
})
非常感谢任何帮助!
答案 0 :(得分: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
})
})
答案 1 :(得分:2)
添加此行
cell.societyImage.layer.masksToBounds = false
cell.societyImage.layer.shadowRadius = 2
答案 2 :(得分:0)
您应该设置以下参数,
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;