Skip to content

Instantly share code, notes, and snippets.

@ricardopereira
Last active July 19, 2023 16:59
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ricardopereira/3637def84a671aad3cb1 to your computer and use it in GitHub Desktop.
Save ricardopereira/3637def84a671aad3cb1 to your computer and use it in GitHub Desktop.
Apply vertical mask alpha gradient to UITableView
let gradient = CAGradientLayer()
gradient.frame = tableView.superview?.bounds ?? CGRectNull
gradient.colors = [UIColor.clearColor().CGColor, UIColor.clearColor().CGColor, UIColor.blackColor().CGColor, UIColor.blackColor().CGColor, UIColor.clearColor().CGColor, UIColor.clearColor().CGColor]
gradient.locations = [0.0, 0.15, 0.25, 0.75, 0.85, 1.0]
tableView.superview?.layer.mask = gradient
tableView.backgroundColor = UIColor.clearColor()
@CristianMoisei
Copy link

This is brilliant, thanks for sharing it.

@scott-lydon
Copy link

This is the only snippet I've found that does what I'm aiming to have done. For some reason though, it is chopping off the right side of my table's contents... its odd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment