How to use Gradient color in UIView in iOS?

Total Post:214


 1217  View(s)
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. 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


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.