-3

I would like to set a transparent black background colour for a UILabel.

CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = label.frame;
[label.layer addSublayer:gradient];

Can I use a gradient to achieve this? Or should I use some other method? Please help me achieve this effect.

I would like to achieve the below effect:

enter image description here

Mark
  • 7,167
  • 4
  • 44
  • 68
Kishore Kumar
  • 4,265
  • 3
  • 26
  • 47

3 Answers3

2

How about this?

label.backgroundColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.7];

What you will adjust is alpha:0.7

Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
2

Just set the backgroundColorproperty of your UILabelto a color with an alpha channel different from 1 :

label.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5f];
Michaël Azevedo
  • 3,874
  • 7
  • 31
  • 45
1

set simple like

label.opaque = NO;

the above choice is not work try

   yourLabel.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.4];

Obviously you can change the RGB colors to what you want.

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143