我有一个简单的问题,我找不到解决方案在谷歌,文档或这里。在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