[英]UICollectionView cell drawing issues swift
在我的項目中,我有uicolelctionview
和自定義單元格。 在collectionView:CellForItemAtIndexPath
我獲得了自定義單元格
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! CustomCollectionCell
並添加此代碼
cell.personImage.layer.cornerRadius=(cell.bounds.size.height-10)/2
cell.personImage.layer.borderWidth=3
cell.personImage.layer.masksToBounds=true
我希望得到這種看法:
但是某些單元格顯示如下:
我必須reloatData來獲取當前的單元格視圖。 仍然不明白為什么我得到這個錯誤
之所以看到形狀像“菱形”的圖像,是因為cornerRadius
目前設置為動態int,並且設置為一半以上。 您應該使用的cornerRadius應該比(cell.bounds.size.height-10)/2
少得多。
正如邁克爾所說,請嘗試使用類似以下內容的方法:
cell.personImage.layer.cornerRadius = testView.frame.width / 2
看看你的結果是什么。
您可以嘗試使用以下代碼設置動態拐角半徑:
cell.personImage.layer.cornerRadius = cell.personImage.frame.width / 2.0
希望這可以幫助 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.