我编写了以下代码来下载图像并将其显示在 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,那么你将看不到阴影,因为它会剪切子层,而如果设置为 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
})
})
关于ios - 阴影未出现在 UIImageView 下(Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37567928/