![](/img/trans.png)
[英]UICollection view in image background as transparent without making the cells in it transparent in Swift
[英]How can I make the background of UICollection view as transparent without making the cells in it transparent in Swift
我有一個集合視圖,當然我也有單元格。 如果在屬性檢查器中我將集合視圖的alpha更改為0,則其中的單元格也變為透明。 有沒有辦法讓背景對集合視圖透明,以便它后面的圖像可見?
UICollectionViewCell
的背景默認為清除。 只需在界面構建器或子類中為您的單元格設置背景顏色,使用:
self.backgroundColor = UIColor.WhiteColor()
在Swift 3中使用:
collectionView.backgroundColor = UIColor.clear.withAlphaComponent(0)
您可以更改單元格顏色以清除並將背景設置為nil以查看collectionView下面的內容。 像這樣:
collectionview.backgroundView = nil;
collectionview.backgroundColor = [UIColor clearColor];
在UICollectionView中,在屬性檢查器中將背景顏色設置為clearcolor。
從屬性檢查器中將UICollectionView
的Opacity刪除為0
將使其成為transperent。
PS:
不好的做法,但會奏效。
如果將集合視圖不透明度拖放到0,則整個集合視圖將不可見。 在您的情況下,您只想顯示集合視圖單元格,因此集合視圖單元格的背景視圖應為UIColor.clear集合視圖背景。 這樣編程
self.collectionView.backgroundView?.backgroundColor = UIColor.clear
self.collectionView.backgroundColor = UIColor.clear
在我的情況下,我需要顯示這樣的聊天記錄,所以我使用了該代碼
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.