If you use the layer property of your scroll view (or any UIView), you can easily get a solid border ...
#import <QuartzCore/QuartzCore.h> ... myView.layer.borderWidth = 2; myView.layer.borderColor = [UIColor blackColor].CGColor;
You can also use a layer to apply shadows in real time by setting the properties of layer.shadow* , but performance can be slow with this technique, so I usually prefer to use the following more complex, but more efficient technique. You can create a PNG image with transparency in the middle and shadow around the edge - it should have 9 different areas: 4 for each corner, 4 for each edge and a completely transparent 1x1 size in the middle. For example, if your shadow extends 6 pixels in your image, your image will be 13x13 with borders of 6 pixels / tall and 1x1 in the middle. Then you set it as a scalable image using:
newImage = [image stretchableImageWithLeftCapWidth:6 topCapHeight:6];
UPDATE:. Since iOS 5.0 stretchableImageWithLeftCapWidth:topCapHeight: deprecated, use it only if you still want to support iOS 4.x devices. If you want to support only iOS 5.0+ devices, use this instead:
newImage = [image resizableImageWithCapInsets:UIEdgeInsetsMake(6, 6, 6, 6)];
Then you put the image in the parent view so that it occupies the entire scroll area. If you want the shadows to go over your scrollable elements (so that your scroll view looks like an insert / behind the rest of the page), then place a transparent UIView on top of the top with a shadow image on it so that it appears in your scroll view behind it.
jhabbott
source share