Skip to content

Instantly share code, notes, and snippets.

@dtrauger
Last active June 24, 2020 14:45
Show Gist options
  • Save dtrauger/5722782 to your computer and use it in GitHub Desktop.
Save dtrauger/5722782 to your computer and use it in GitHub Desktop.
Create Gradient Background for View in Objective C
// Create the colors
UIColor *topColor = [UIColor colorWithRed:50.0/255.0 green:50.0/255.0 blue:50.0/255.0 alpha:1.0];
UIColor *bottomColor = [UIColor colorWithRed:56.0/255.0 green:56.0/255.0 blue:56.0/255.0 alpha:1.0];
// Create the gradient
CAGradientLayer *theViewGradient = [CAGradientLayer layer];
theViewGradient.colors = [NSArray arrayWithObjects: (id)topColor.CGColor, (id)bottomColor.CGColor, nil];
theViewGradient.frame = theView.bounds;
//Add gradient to view
[theView.layer insertSublayer:theViewGradient atIndex:0];
@radorbit
Copy link

@goel232 use "startPoint" and "endPoint" properties on CAGradientLayer.

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