Search code examples
iphoneiosxcode4

Glow Effect on rectangle in iPad


I have take a lot of patient and make the rectangle in glow effect as per my requirement.

CALayer *bevelLayer = [CALayer layer];
[bevelLayer setBounds:CGRectMake(0.0f, 0.0f, 300.0f, 300.0f)];
[bevelLayer setPosition:CGPointMake(300.0f, 550.0f)];

[bevelLayer setBackgroundColor:[[UIColor whiteColor] CGColor]];
[bevelLayer setShadowOpacity:1.0];
[bevelLayer setShadowRadius:7.0f];
[bevelLayer setShadowColor:[[UIColor colorWithRed:0.0f/255.0  green:126.0f/255.0f        blue:255.0f/255.0f alpha:1.0f] CGColor]];
[bevelLayer setShadowPath:[[UIBezierPath bezierPathWithRoundedRect:CGRectMake(-10.0f, -10.0f, 310.0f, 310.0f) cornerRadius:5.0f] CGPath]];
[[[self view] layer] addSublayer:bevelLayer];

Solution

  • Instead of adding a new layer, why dont you directly try it on self.view.. Also, shadowOpacity is a value between 0 and 1... So giving 10 is definitely not going to help you.

    If you want to try in self.view, here is the code:

    self.view.layer.shadowColor = [[UIColor greenColor] CGColor];
    self.view.layer.shadowOffset = CGSizeMake(1, 1);
    self.view.layer.shadowOpacity = 1;
    self.view.layer.shadowRadius = 20;
    

    This way you dont have to worry about the bounds of the layer..