The following code seems to work using Objective-C however its Swift version doesn't work.
I have tried the following:
- Add the gradient inside the collection view cell
- Add the gradient in the viewController
- Use UIColor & CGColor
Use insertSubLayer
var mGradient = CAGradientLayer() mGradient.frame = favoriteCell.mImageView.bounds var colors = [CGColor]() colors.append(UIColor(red: 0, green: 0, blue: 0, alpha: 1).CGColor) colors.append(UIColor(red: 0, green: 0, blue: 0, alpha: 0).CGColor) mGradient.startPoint = CGPointMake(0.1, 0.5) mGradient.endPoint = CGPointMake(0.9, 0.5) favoriteCell.mImageView.layer.addSublayer(mGradient)