【问题标题】:Shadow not appearing under UIImageView (Swift)UIImageView(Swift)下没有出现阴影
【发布时间】:2016-09-30 18:40:41
【问题描述】:

我编写了以下代码来下载并在 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
})

非常感谢任何帮助!

【问题讨论】:

  • 将 shadowradius 和 clipsToBound 属性添加到您的代码中,将解决您的问题。

标签: ios swift uiimageview shadow


【解决方案1】:

关于maskToBounds:如果你把它设置为true,那么你将不会看到阴影,因为它会剪切子层,否则它允许扩展层。

...    
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】:

    添加这一行

    cell.societyImage.layer.masksToBounds = false
    
    cell.societyImage.layer.shadowRadius = 2
    

    【讨论】:

      【解决方案3】:

      你应该设置以下参数,

       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;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-12-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多