UICollectionview上的四角而不是单个单元格

时间:2016-10-18 16:39:23

标签: ios uicollectionview uicollectionviewcell uibezierpath rounded-corners

我试图在UICollectionView

上设置2个圆角顶角

我有UIView contentView ,其中包含我的UICollectionView。如果我将UICollectionView的cornerRadius设置为true并将clipsToBound设置为true,则除了将所有4个角落进行舍入之外,这是有效的。

所以看起来我需要应用UIBezierPath但是一旦我这样做,我遇到了问题:

  1. 如果我将UIBezierPath应用于UICollectionView本身,我只能看到我的第一个单元格,当我滚动到第二个单元格时,我看不到任何内容。
  2. [

    [UIBezierPath bezierPathWithRoundedRect:self.collectionView.bounds
     byRoundingCorners:UIRectCornerTopLeft cornerRadii:CGSizeMake(9.0,
     9.0)];     
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.frame = self.collectionView.bounds;
    maskLayer.path = maskPath.CGPath;
    self.collectionView.layer.mask = maskLayer;
    
    1. 如果我尝试将UIBezierPath应用于 contentView ,与上述相同,但我将 self.collectionView 替换为 self.contentView < / strong>,角落根本不圆。

2 个答案:

答案 0 :(得分:0)

如何舍入您的collectionView所在的视图?

这样的事情:

let viewFrame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
let corners: UIRectCorner = .topLeft
let path = UIBezierPath(
    roundedRect: viewFrame,
    byRoundingCorners: corners,
    cornerRadii: CGSize(width: 50, height: 50))
let maskLayer = CAShapeLayer()
maskLayer.frame = viewFrame
maskLayer.path = path.cgPath
view.layer.mask = maskLayer 

答案 1 :(得分:0)

只要父视图不是我的第一个/顶部视图,就可以在UIBezierPath父容器上设置UICollectionView。我必须在我的热门UIView添加另一个UIView roundContainerView

UIView ( Top view. contentView )

  |- UIView ( roundContainerView ) apply UIBezierPath here

       |- UICollectionView ( collectionView )