To add a background gradient to UILabel, I use the following code.
Before using the gradient, UILabel appears as follows.
Now, to add a gradient, I use the following code.
CAGradientLayer *gradLayer=[CAGradientLayer layer];
gradLayer.frame=self.myView.layer.bounds;
[gradLayer setColors:[NSArray arrayWithObjects:(id)([UIColor redColor].CGColor), (id)([UIColor cyanColor].CGColor),nil]];
gradLayer.endPoint=CGPointMake(1.0, 0.0);
[self.myView.layer addSublayer:gradLayer];
Then UILabel looks like this, but without text.
I am also trying to add a layer at the bottom of the UILabel layer, but have not succeeded.
[self.myView.layer insertSublayer:gradLayer atIndex:0]
source
share