[英]How can I add line under Row of UICollectionView, Swift 5, Xcode
正如 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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.