iOS:表格单元格页脚阴影

发布于 2025-01-05 19:50:52 字数 589 浏览 3 评论 0原文

我有一个只有几行的表格视图。因此,我没有显示一堆空白,而是向 tableview.footer 添加了一个空白 UIView。但是我希望最后一个单元格在 UIView 上投射阴影。我将如何实现这一目标?这是我当前的代码。

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIView *emptyView = [[UIView alloc] initWithFrame:CGRectZero];
    CALayer *layer = [emptyView layer];
    [layer setShadowOffset:CGSizeMake(0, 1)];
    [layer setShadowColor:[[UIColor darkGrayColor] CGColor]];
    [layer setShadowRadius:8.0];
    [layer setShadowOpacity:0.8];
    self.tableView.tableFooterView = emptyView;
}

编辑: 它将 UIView 添加到页脚,但不创建阴影。我不确定该层是解决此问题的最佳方法,甚至不确定该方法是否正确。

I have a tableview with only a few rows. So instead of displaying a bunch of blanks I added a blank UIView to the tableview.footer. However I would like the last cell to cast a dropshadow on the UIView. How would I achieve this? Here is my current code.

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIView *emptyView = [[UIView alloc] initWithFrame:CGRectZero];
    CALayer *layer = [emptyView layer];
    [layer setShadowOffset:CGSizeMake(0, 1)];
    [layer setShadowColor:[[UIColor darkGrayColor] CGColor]];
    [layer setShadowRadius:8.0];
    [layer setShadowOpacity:0.8];
    self.tableView.tableFooterView = emptyView;
}

EDIT:
It is adding the UIView to the footer but not creating the dropshadow. I'm not sure the layer is the best approach for this or even correct for this type of thing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

帅气称霸 2025-01-12 19:50:52

这可能是因为你将框架设置为CGRectZero。

零矩形相当于 CGRectMake(0,0,0,0)。

零矩形 (x=0, y=0, width=0, height=0) 的阴影不会完全显示。

尝试给它一个合适的框架大小,你会看到差异。

也请查看此参考:https: //developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CGGeometry/Reference/reference.html

It is probably because you set the frame to CGRectZero.

The zero rectangle is equivalent to CGRectMake(0,0,0,0).

A shadow of a zero rect (x=0, y=0, width=0, height=0) won't show at all.

Try giving it a proper frame size and you will see the difference.

Check out this for ref as well: https://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CGGeometry/Reference/reference.html

屋檐 2025-01-12 19:50:52

我最终使用了

shadowBackgroundView.layer.shadowOpacity = 0.3; 
shadowBackgroundView.layer.shadowRadius = 2;
shadowBackgroundView.layer.shadowColor = [[UIColor blackColor] CGColor];
shadowBackgroundView.layer.shadowOffset = CGSizeMake(0.0, 1.0);
CGPathRef shadowPath = [UIBezierPath bezierPathWithRoundedRect: shadowBackgroundView.bounds 
                                                         byRoundingCorners: UIRectCornerAllCorners
                                                               cornerRadii: CGSizeMake(PageCellBackgroundRadius, PageCellBackgroundRadius)].CGPath;
shadowBackgroundView.layer.shadowPath = shadowPath;
shadowBackgroundView.layer.shouldRasterize = YES;

[self addSubview: shadowBackgroundView];

I ended up using

shadowBackgroundView.layer.shadowOpacity = 0.3; 
shadowBackgroundView.layer.shadowRadius = 2;
shadowBackgroundView.layer.shadowColor = [[UIColor blackColor] CGColor];
shadowBackgroundView.layer.shadowOffset = CGSizeMake(0.0, 1.0);
CGPathRef shadowPath = [UIBezierPath bezierPathWithRoundedRect: shadowBackgroundView.bounds 
                                                         byRoundingCorners: UIRectCornerAllCorners
                                                               cornerRadii: CGSizeMake(PageCellBackgroundRadius, PageCellBackgroundRadius)].CGPath;
shadowBackgroundView.layer.shadowPath = shadowPath;
shadowBackgroundView.layer.shouldRasterize = YES;

[self addSubview: shadowBackgroundView];
写下不归期 2025-01-12 19:50:52

cellForRowAtIndexPath: 函数中:

// drop shadow
cell.layer.shadowOpacity = 1.0;
cell.layer.shadowRadius = 1.7;
cell.layer.shadowColor = [UIColor blackColor].CGColor;
cell.layer.shadowOffset = CGSizeMake(0.0, 0.0);

In cellForRowAtIndexPath: function:

// drop shadow
cell.layer.shadowOpacity = 1.0;
cell.layer.shadowRadius = 1.7;
cell.layer.shadowColor = [UIColor blackColor].CGColor;
cell.layer.shadowOffset = CGSizeMake(0.0, 0.0);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文