如何在UICollectionView的行下添加行,Swift 5,Xcode

问题描述 投票:0回答:2

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

我要逐行分开。CollectionView with CollectionViewCell and in right side running on emulator.

ios swift xcode uicollectionview uicollectionviewcell
2个回答
1
投票

由于UICollectionView的单元格没有分隔符,您可以仅在适合页面设计的情况下才切换到UITableView,或者可以通过在UICollectionViewCell中使用UIView添加分隔符底部高度为1。您也可以尝试在GitHub上找到一些第三方解决方案,例如:Solution 1Solution 2


0
投票
  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)

© www.soinside.com 2019 - 2024. All rights reserved.