I have a UITableView where my backgroundView cell is equal to UIImageView . I would like each of the images to fade to black so that I can overlay some white text.
I reviewed some answers, such as, but no one works.
In tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) I tried:
var imageView = UIImageView(image: image) var gradient: CAGradientLayer = CAGradientLayer() gradient.frame = imageView.frame gradient.colors = [UIColor.blackColor(), UIColor.clearColor()] gradient.locations = [0.0, 0.1] imageView.layer.insertSublayer(gradient, atIndex: 0) cell!.backgroundView = imageView
But I do not see the gradient and is no different from when I delete the gradient code. Is my gradient below the image?
If I replace the line imageView.layer.insertSublayer(gradient, atIndex: 0) with imageView.layer.mask = gradient , then my cells will be empty and white (there is no image anymore).
ios swift uiimageview cagradientlayer
Imran
source share