繁体   English   中英

Swift中具有角半径的集合视图

[英]Collection View with corner radius in Swift

我有一个 CollectionViewController,我想将角半径设置为 CollectionView(标题视图下方的部分)。

在此处输入图像描述

这就是我想要的(黄色的角半径)。 可能吗? 你知道我该怎么做吗?

        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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM