【问题标题】:Collection View with corner radius in SwiftSwift中具有角半径的集合视图
【发布时间】:2017-10-24 12:29:13
【问题描述】:

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

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

【问题讨论】:

  • 您在互联网上有很多解决方案。尝试其中任何一个,如果您遇到任何错误,我们会在这里为您提供帮助。
  • 你可以为你的collectionview设置清晰的颜色并将圆角半径设置为collectionviewcell..

标签: ios swift swift3 uicollectionview rounded-corners


【解决方案1】:
        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)

【讨论】:

  • 谢谢,但您的回答不适用于标题视图
【解决方案2】:

解决方案非常简单。 我刚刚删除了 collectionViewLayout 顶部的插图,并向 HeaderView 添加了一个新视图。 之后,我将圆角半径应用于添加的视图,它工作了:)

【讨论】:

    猜你喜欢
    • 2018-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-14
    • 1970-01-01
    • 1970-01-01
    • 2018-01-15
    • 1970-01-01
    相关资源
    最近更新 更多