簡體   English   中英

UICollectionView單元格繪制問題迅速

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM