0

I have this code here,

label.layer.shadowColor = [UIColor orangeColor].CGColor;
label.layer.shadowOffset = CGSizeMake(0,1);
label.layer.shadowRadius = 3.0;
label.layer.shadowOpacity = 0.5;
label.layer.shadowPath = [[UIBezierPath bezierPathWithRoundedRect:label.frame cornerRadius:20]CGPath];

I am using orange for testing purposes. Why is this not appearing as a shadow? All I am seeing is this, http://img12.imageshack.us/img12/1568/screenshot20130312at415.png

I am trying to get the gray label on the inside to have a shadow around the edges... Any help?

-Henry

2 Answers2

2

You need to use label.bounds, not label.frame, to create the path. Also, make sure label.clipsToBounds is NO.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • When I do, http://pastebin.com/ENGpRfq6 It does add the shadow, but it removes the rounded corners. –  Mar 12 '13 at 22:54
1

Try setting shadowOffset -1

label.layer.shadowOpacity = 1.0;
label.layer.shadowRadius =2.0;
label.layer.shadowColor = [UIColor blackColor].CGColor;
label.layer.shadowOffset = CGSizeMake(0.01,-1.0);

Also set label.bounds instead of label.frame

label.layer.shadowPath = [[UIBezierPath bezierPathWithRoundedRect:label.bounds cornerRadius:20]CGPath];
nsgulliver
  • 12,655
  • 23
  • 43
  • 64
  • Weird... And it keeps the rounded corners? –  Mar 12 '13 at 23:23
  • Shadow with color has appeared right, I am not by computer now , I didn't notice radius but I can have a look once I am by computer – nsgulliver Mar 12 '13 at 23:27
  • 1
    Even shadow color not appearing for you? – nsgulliver Mar 12 '13 at 23:36
  • @HenryHarris I have tested the code in my app and it shows the rounded corners for the radius as well, you must be having some other issue, you should break down your code into smaller steps. if you create a new project and add label to a the interface and use this code it will work! – nsgulliver Mar 13 '13 at 13:48