Reputation: 2265
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.
How would I best achieve the effect I'm looking for on a UITableView?
Upvotes: 0
Views: 2433
Reputation: 2265
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];
}
Upvotes: 2
Reputation: 15410
This post, I believe, covers exactly what you are looking for:
http://cocoawithlove.com/2009/08/adding-shadow-effects-to-uitableview.html
Upvotes: 0