Ios UIImageView(Swift)下未出现阴影
我编写了以下代码来下载并在tableView的单元格中显示图像。然而,阴影根本没有出现,我也不知道是什么问题Ios UIImageView(Swift)下未出现阴影,ios,swift,uiimageview,shadow,Ios,Swift,Uiimageview,Shadow,我编写了以下代码来下载并在tableView的单元格中显示图像。然而,阴影根本没有出现,我也不知道是什么问题 cell.societyImage.setIndicatorStyle(UIActivityIndicatorViewStyle.White) cell.societyImage.setShowActivityIndicatorView(true) cell.societyImage.sd_setImageWithURL(NSURL(string: pictureURLs[objectI
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,则在剪辑子层时不会看到阴影,否则为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.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;
将shadowradius和clipsToBound属性添加到代码中,将解决您的问题。