0

I am trying to add gradient layer behind the UILabel's text which resides in a custom UITableViewCell. Problem is that gradient is hiding my label's text. I have already visited this link, but it is not working for me.So how can I add it behind the text layer?

What I have done so far is:

CAGradientLayer *gradient = [CAGradientLayer layer];
    gradient.frame = CGRectMake(0, 0,  buyPrice_port.frame.size.width,  buyPrice_port.frame.size.height);
    gradient.colors = [NSArray arrayWithObjects:(id)gainBackgroundColor1, (id)gainBackgroundColor2, nil];
    gradient.locations = [NSArray arrayWithObjects: [NSNumber numberWithFloat:0.00], [NSNumber numberWithFloat:0.70] , nil];
    [buyPrice_port.layer insertSublayer:gradient atIndex:0];
    buyPrice_port.textColor = [UIColor blackColor];
Community
  • 1
  • 1
NightFury
  • 13,436
  • 6
  • 71
  • 120

1 Answers1

1

You can simply add a view behind the UILabel (i.e. add the label as a subview of the gradient view) and keep the label transparent.

Mundi
  • 79,884
  • 17
  • 117
  • 140