0

I draw a shadow behind a UIView using the following code

    self.view.layer.borderColor = [UIColor whiteColor].CGColor;
    self.view.layer.shadowColor = [UIColor blackColor].CGColor;
    self.view.layer.shadowOpacity = 1.0;
    self.view.layer.shadowRadius = 25.0;
    self.view.layer.shadowOffset = CGSizeMake(0, 3);
    self.view.clipsToBounds = NO;

    CGPathRef shadowPath = [UIBezierPath bezierPathWithRect:self.view.layer.bounds].CGPath;
    [self.view.layer setShadowPath:shadowPath];

This works as supposed in the Simulator and on the iPhone5. However on my iPad3: No Shadow at all.

enter image description here

Any idea how come?

Bernd
  • 11,133
  • 11
  • 65
  • 98

1 Answers1

0

I found the solutions. It wasn't about the Simulator. It was about the return of bounds in portrait vs. landscapt orientation. I had to move the setting of the shadow path into the viewDidAppear and the didRotateFromInterfaceOrientation method to have the shadow render correctly in all possible startup orientations.

-(void)viewDidAppear:(BOOL)animated{
    CGPathRef shadowPath = [UIBezierPath bezierPathWithRect:self.view.layer.bounds].CGPath;
    [self.view.layer setShadowPath:shadowPath];
}

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    CGPathRef shadowPath = [UIBezierPath bezierPathWithRect:self.view.layer.bounds].CGPath;
    [self.view.layer setShadowPath:shadowPath];
}
Bernd
  • 11,133
  • 11
  • 65
  • 98