potato
potato

Reputation: 4589

custom collectionViewCell's selectedBackgroundView with rounded corners

I'm trying to create a custom selectedBackgroundView for my collectionView cell. I subclassed the UIView and this is my drawRect implementation:

override func drawRect(rect: CGRect) {
        let context = UIGraphicsGetCurrentContext()
        CGContextSaveGState(context)
        let bezierPath = UIBezierPath(roundedRect: rect, cornerRadius: 5.0)
        bezierPath.lineWidth = 5
        let color = UIColor(red: 0, green: 0, blue: 0, alpha: 0)
        color.setStroke()

        UIColor(red:0.529, green:0.808, blue:0.922, alpha:1).setFill()
        bezierPath.fill()
        bezierPath.stroke()
        CGContextRestoreGState(context)
    }

The following image depicts what I get when the cell is selected.

enter image description here

As you can see, I'm getting this ugly black corners. I want the black corners to be fully transparent. How can I acchieve that? Thanks for your help.

Upvotes: 0

Views: 284

Answers (1)

Aurast
Aurast

Reputation: 3688

You can set the view's layer's cornerRadius to 5.

self.view.layer.cornerRadius = 5;

And set the view's clipsToBounds property to true.

self.view.clipsToBounds = true;

Upvotes: 1

Related Questions