Swift中带角半径的集合视图

问题描述 投票:-1回答:2

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

enter image description here

这就是我想要的(角半径为黄色)。可能吗?你对我怎么做到这一点有什么想法吗?

ios swift swift3 uicollectionview rounded-corners
2个回答
3
投票
        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)

0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.