裁切影象設定圓角影象,不使用控制元件的layer.cornerRadius屬性
阿新 • • 發佈:2019-02-02
//placeHolderImage
佔位圖片
var placeHolderImage:
UIImage?
if placeHolderName != nil {
placeHolderImage = UIImage(named: placeHolderName!)
}
//如果URL為nil
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
})
}
if placeHolderName != nil {
placeHolderImage = UIImage(named: placeHolderName!)
}
//如果URL為nil
guard let urlString = urlString,
let url = NSURL(string: urlString)
// 如果 urlString 為nil,但是指定了佔位影象,顯示佔位影象 image = placeHolderImage
return
}
//判斷 裁剪尺寸 if size == CGSizeZero {
sd_setImageWithURL(url , placeholderImage: placeHolderImage)
return
}
return
}
// 2. 對影象進行裁切 image.lzj_asyncDrawImage
})
}