UITableView层上的内部阴影? [英] Inner shadow on UITableView layer?

查看:261
本文介绍了UITableView层上的内部阴影?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要添加一个内部阴影效果到我的UITableView。我发现了有关向UIView图层添加内部阴影的有用文章:



然后指示新的UIView子类通过实现以下方法将所有触摸事件转发到基础视图控制器:

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



最后,我将新视图作为子视图添加到我的主视图中,set

   - (void)viewDidLoad { 
InnerShadowView * shadowView = [[InnerShadowView alloc] init];
[self.view addSubview:shadowView];
shadowView.frame = _tableView.frame;
shadowView.backgroundColor = [UIColor clearColor];
[self.view bringSubviewToFront:shadowView];
}


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?

解决方案

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];
}

这篇关于UITableView层上的内部阴影?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆