我有一個簡單的問題,我找不到解決方案在谷歌,文檔或這裏。在UICollectionViewCell中的UIimage在swift中設置圓角
我在我的視圖控制器中有一個CollectionView。我創建了一個包含UIImage的自定義單元DescriptionCell。我希望這個圖像有圓角。但是,我不知道在UIImage圖層上設置角點的位置。我試過在單元的awakeFromNib方法中,在委託方法CellForRowAtIndexPath中並覆蓋單元格中的LayoutSubview,但它不起作用。 我應該在哪裏設置UIImage的半徑代碼?
要指定,我知道如何創建UIImage的圓角。但如果它是一個Collectionview單元格的子視圖,我不知道在哪裏設置cornerradius。
這裏是代碼爲我descriptionCell
class DescriptionCell: UICollectionViewCell {
@IBOutlet weak var mImage: UIImageView!
override func awakeFromNib() {
//mImage.layer.cornerradius = 5
//Does not work, the image is still square in the cell
}
而在cellforRowAtIndePath
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
var cell = collectionView.dequeueReusableCellWithReuseIdentifier("descriptioncell", forIndexPath: indexPath) as! DescriptionCell
//cell.mImage.layer.cornerradius = 5
//Does not work, the image is still square in the cell
return cell
}
提前感謝!
的可能的複製[爲UIImage製作圓角](http://stackoverflow.com/questions/8938800/making-round-corners-for-a-uiimage) – Hama
不,這是不同的。我已經在使用該答案中的代碼。我的問題是在哪裏把UIImage.layer.cornerradius = xxx? – Jell92
用相關代碼更新您的問題。 – rmaddy