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