簡體   English   中英

如何在 UICollectionView、Swift 5、Xcode 行下添加行

[英]How can I add line under Row of UICollectionView, Swift 5, Xcode

如何在 UICollectionView、Swift 5、Xcode 行下添加行?

我想逐行分開。 帶有 CollectionViewCell 的 CollectionView 和在模擬器上運行的右側。

由於UICollectionView的單元格沒有分隔符,因此您可以切換到UITableView僅當它適合您的頁面設計時,或者您可以通過在底部使用高度為 1 的UIViewUICollectionViewCell添加分隔符。還有一些您可以嘗試在 GitHub 上找到的第三方解決方案,例如: 解決方案 1解決方案 2

  1. 正如 Ayazmon 所說,您可以將 UIView 添加到高度為 1 的單元格中。

  2. 您可以為單元格添加底部邊框。

     extension CALayer { func addBorder(edge: UIRectEdge, color: UIColor, thickness: CGFloat) { let border = CALayer() switch edge { case .top: border.frame = CGRect(x: 0, y: 0, width: frame.width, height: thickness) case .bottom: border.frame = CGRect(x: 0, y: frame.height - thickness, width: frame.width, height: thickness) case .left: border.frame = CGRect(x: 0, y: 0, width: thickness, height: frame.height) case .right: border.frame = CGRect(x: frame.width - thickness, y: 0, width: thickness, height: frame.height) default: break } border.backgroundColor = color.cgColor addSublayer(border) } }

然后

cell.layer.addBorder(edge: .bottom, color: .black, thickness: 1)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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