Search code examples
iphoneioscalayershadow

Shadow left and right of UIView


Hi i like to add an CALayer Shadow to an View where the shadow was left and right of the view the simplest way was:

someView.layer.shadowColor = [[UIColor blackColor] CGColor];
someView.layer.shadowOffset = CGSizeMake(0.0f,0.0f);
someView.layer.shadowOpacity = 1.0f;
someView.layer.shadowRadius = 10.0f;
someView.layer.shadowPath = [[UIBezierPath bezierPathWithRect:someView.bounds] CGPath];

but i will add a bigger shadow as like a shadow when i increase the shadowRadius it do not look good. How i can make a shadow that looks good at left and right.


Solution

  • I think 10 is a pretty big shadow radius, try 3 or 4 instead, also opacity I usually use 0.7:

    someView.layer.shadowColor = [[UIColor blackColor] CGColor];
    someView.layer.shadowOffset = CGSizeMake(0.0f,0.0f);
    someView.layer.shadowOpacity = 0.7f;
    someView.layer.shadowRadius = 4.0f;
    

    If you want the shadow only on left and right, then inset the rectangle on the top and bottom so the top and bottom shadow are hidden behind your view:

    CGRect shadowRect = CGRectInset(someView.bounds, 0, 4);  // inset top/bottom
    someView.layer.shadowPath = [[UIBezierPath bezierPathWithRect:shadowRect] CGPath];
    

    I'm not really sure if that's what you wanted.