0

I need to add an inner shadow effect to my UITableView. I've discovered this helpful post on adding an inner shadow to a UIView layer: Inner shadow effect on UIView layer?

The problem arises when I attempt to use this technique on a UITableView because the UITableView's cells are displayed on top, covering the shadow.

I've played around with adding the UITableView as a subview to a UIView (with the inner shadow) to no effect.

My UITableView is centered on the UIViewController's view with a dark gray background. Giving the UITableView an inner shadow would give the background the effect of being a bezel for the table view.What I currently have WITHOUT the inner shadow

How would I best achieve the effect I'm looking for on a UITableView?

Community
  • 1
  • 1
docksteaderluke
  • 2,195
  • 5
  • 27
  • 38

2 Answers2

2

Answering my own question:

I ended up subclassing a UIView and implementing the drawRect function using this post: Inner shadow effect on UIView layer?

Then instructed the new UIView subclass to forward all touch events through to the underlying view controllers by implementing the following method:

-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
    return NO;
}

Finally, I added the new view as a subview to my main view, set its background to be transparent, positioned it on top of the tableView and brought it to the front.

- (void)viewDidLoad {
    InnerShadowView *shadowView = [[InnerShadowView alloc] init];
    [self.view addSubview:shadowView];
    shadowView.frame = _tableView.frame;
    shadowView.backgroundColor = [UIColor clearColor];
    [self.view bringSubviewToFront:shadowView];
}
Community
  • 1
  • 1
docksteaderluke
  • 2,195
  • 5
  • 27
  • 38
0

This post, I believe, covers exactly what you are looking for:

http://cocoawithlove.com/2009/08/adding-shadow-effects-to-uitableview.html

Clafou
  • 15,250
  • 7
  • 58
  • 89
  • I _think_ I see what you wish to do. If what I understand is right, you could make the grey frame a static image overlay on top of your UITableView and edit its image so that it includes a semi-transparent shadow just beneath the top edge. It doesn't have to be a full-page image, you could use a stretchable image such as described here: http://idevrecipes.com/2010/12/08/stretchable-images-and-buttons/ – Clafou Sep 26 '12 at 14:17