HOW TO USE GRADIENT COLOR IN UIVIEW IN IOS?

Tarun Kumar

Total Post:214

Points:1642
Posted by  Tarun Kumar
 689  View(s)
Ratings:
Rate this:
I want to create gradient color and want to use it into our UIView. 
Can anyone tell me how can I generate a view with gradient color background in runtime.
If is there any way to do that then please provide me the code also.
  1. Glen Martin

    Post:27

    Points:191
    Re: How to use Gradient color in UIView in iOS?

    The code I am providing here is already running in my own application, so I hope my code is helpful for you:

    CAGradientLayer *gradient = [CAGradientLayer layer];
    gradient.frame = selectedView.bounds;
    gradient.colors = [NSArray arrayWithObjects:
        (id)[[UIColor blackColor] CGColor],
        (id)[[UIColor greenColor] CGColor],
        (id)[[UIColor redColor] CGColor], nil];

    our gradient color is created, now we assign it in our view layer, like this:

    [view.layer insertSublayer:gradient atIndex:0];

      Modified On Dec-30-2015 10:58:13 PM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!