1. 程式人生 > >裁切影象設定圓角影象,不使用控制元件的layer.cornerRadius屬性

裁切影象設定圓角影象,不使用控制元件的layer.cornerRadius屬性

//placeHolderImage 佔位圖片 var placeHolderImage: UIImage?
       
       
if placeHolderName != nil {
           
            placeHolderImage =
UIImage(named: placeHolderName!)
        }
       
       
//如果URLnil
guard let urlString = urlString,
           
let url = NSURL(string: urlString)
else {
           
// 如果 urlString nil,但是指定了佔位影象,顯示佔位影象 image = placeHolderImage
           
           
return
        }
       
//判斷 裁剪尺寸 if size == CGSizeZero {
               
              
sd_setImageWithURL(url , placeholderImage: placeHolderImage)
              
return
            }
       
// 對影象進行裁切,提示:從網路不一定能夠獲取到影象          sd_setImageWithURL(url,  placeholderImage: placeHolderImage) { (image, _, _, _) -> Void in //1.判斷影象是否存在, guard  let  image = image  else {
                   
return
                }
               
// 2. 對影象進行裁切               image.lzj_asyncDrawImage
(size, isCorner: isCorner, backColor: backColor, finished: { (image) -> () in self.image = image
                 })
            }