Search code examples
objective-cquartz-graphics

Shadow with QuartzCore on iPad


I have a very strange problem when it comes to create shadows with the beautiful framework QuartzCore.

When I put the following code in viewDidLoad and run it on the iPhone Simulator it works perfectly, but when I try to run it in iPad Simulator the shadow isn't there.

self.viewAboutContainer.layer.shadowColor = [[UIColor blackColor] CGColor];
self.viewAboutContainer.layer.shadowOpacity = 0.7;
self.viewAboutContainer.layer.shadowRadius = 4.0;
self.viewAboutContainer.layer.shadowOffset = CGSizeMake(5.0f, 5.0f);    
self.viewAboutContainer.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.viewAboutContainer.bounds].CGPath;

Here the strange part, when i move the code from viewDidLoad to viewWillAppear everything works perfectly on iPad Simulator as well.

Can someone explain to me why?


Solution

  • Very interesting.

    The thing about the simulators is that they are not true device emulators. True device emulators run code and libraries that are actually running on the device. Simulators run code and libraries that were designed to run on, in your case, your Mac computer but only simulate behavior on the actual iOS device. How code behaves in the simulators depends on how true to the actual device the simulator software dev was able to attain.

    I would suggest testing your code on actual iPhone and iPad devices, if you are able. Testing on actual devices will reveal a lot.

    You might also try attaining your shadow effect by embedding a UIView within a UIView containing a shadow image. Whenever I code anything in my apps, I always start with the APIs provided at the highest level and work my way down the Apple provided API stack. I believe this is the way Apple recommends using their APIs.

    Hope this helped. Good Luck.