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.
Any idea how come?
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];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.