[英]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.