2016-06-01 6 views
2

Ich habe den folgenden Code geschrieben, um ein Bild in den Zellen eines TableView zu downloaden und anzuzeigen. Der Schlagschatten erscheint jedoch überhaupt nicht und ich kann nicht herausfinden, was falsch ist.Schatten erscheint nicht unter UIImageView (Swift)

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

Jede Hilfe wird sehr geschätzt!

+0

hinzufügen shadowradius und clipsToBound Eigenschaften, um Ihren Code, wird Ihr Problem gelöst. –

Antwort

5

über maskToBounds: Wenn Sie es ausdrückte wahr ist, dann werden Sie nicht Schatten, wie es Clips Teilschicht sehen, wo sonst in falschem es soweit Schicht ermöglichen.

...  
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 
    }) 
})   
+2

Danke, funktioniert wie ein Charme! –

1

diese Zeilen hinzufügen

cell.societyImage.layer.masksToBounds = false 

cell.societyImage.layer.shadowRadius = 2 
+0

es funktioniert jetzt, danke! –

0

Sie sollten folgende Parameter eingestellt,

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;