[英]Collection View with corner radius in Swift
extension UICollectionView {
func roundCorners(_ corners:UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
self.layer.mask = mask
}}
collectioniew.roundCorners([.topLeft,.topRight], radius: 5)
解决方案非常简单。 我刚刚删除了 collectionViewLayout 顶部的插图,并向 HeaderView 添加了一个新视图。 之后,我将圆角半径应用于添加的视图,它起作用了:)
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! CollectionViewCell
cell.viewCell.layer.cornerRadius = 25.0
cell.viewCell.clipsToBounds = true
return cell
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.