Last active
June 24, 2020 14:45
-
-
Save dtrauger/5722782 to your computer and use it in GitHub Desktop.
Create Gradient Background for View in Objective C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
background Gradient : rgb(118,118,118) | #ffffff | rgb(198,198,197) linear left to right
Hello Sir how can i set my gradient to as required by the client please suggest ??
I have tried this way but it is happening in Vertical direction I want it in Horizontal way
UIColor *leftColor = [UIColor colorWithRed:118.0/255.0 green:118.0/255.0 blue:118.0/255.0 alpha:1.0];
UIColor *middleColor = [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0];
UIColor *rightColor = [UIColor colorWithRed:198.0/255.0 green:198.0/255.0 blue:197.0/255.0 alpha:1.0];