The simplest (rectangular) shadow for UIView

I saw a lot of fragments that are either too complex for something as simple as a shadow, requiring a subclass of UIView and using the quartz2d calls, or I can't get them to work.

I just want to do this in the view that I add as a subtitle for another (subview is taken from another viewController, which I just highlight - I know that it’s probably not very good, but good), no IB or anything . what is the easiest / most acceptable way to do this? would it be different if I want it to work on iOS 4?

+5
source share
1 answer

It is as simple as importing <QuartzCore/QuartzCore.h>and using a similar snippet, as shown below:

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;
+10
source

All Articles