ios - Swift 中带有圆角半径的 Collection View

标签 ios swift swift3 uicollectionview rounded-corners

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

enter image description here

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

最佳答案

        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)

关于ios - Swift 中带有圆角半径的 Collection View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46910642/

相关文章:

ios - 有没有办法访问与 EKEvent 关联的 "Comments"?

ios - 我可以从多个线程绘制到同一个 CGContextRef 吗?

ios - imageView图像返回null

ios - Swift 3.0 中的 Objective C 代码

ios - 我可以从后台线程调用或运行 Core Data Main Context (viewContext) 吗?

ios - 在 IOS 中移动到 View Controller 时出现问题

ios - 如何将数据从弹出 View Controller 发送到主视图 Controller 。传递一个字符串,以便我可以将其作为主视图中的标签文本

swift - 核心数据编码模式

ios - 仅适用于 iPhone 的方向锁定

ios - UITapGestureRecognizer 无法在自定义类内部工作(这不是 View Controller )