How to set gradient color to the background of UILabel in iPhone

cagradientlayer, uilabel

Solution

It working fine when i insert the CAGradientLayer to the main view.

[self.teamName setTextColor:[UIColor whiteColor]];
    [self.teamName setBackgroundColor:[UIColor clearColor]];
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = self.teamName.bounds;
    gradientLayer.colors = [NSArray arrayWithObjects:(id)[[UIColor whiteColor]CGColor], (id)[[UIColor blackColor]CGColor], nil];
    [self.view.layer insertSublayer:gradientLayer atIndex:0];

Problem

I am using the following code to set the gradient color to the background of label but no effect what i am doing wrong? Code is here: ``` [self.teamName setTextColor:[UIColor whiteColor]]; [self.teamName setBackgroundColor:[UIColor clearColor]]; CAGradientLayer *gradientLayer = [CAGradientLayer layer]; gradientLayer.frame = self.teamName.bounds; gradientLayer.colors = [NSArray arrayWithObjects:(id)[[UIColor whiteColor]CGColor], (id)[[UIColor blackColor]CGColor], nil]; [self.teamName.layer insertSublayer:gradientLayer atIndex:0]; ```

Original source