为UITableView创建一个阴影效果 [英] Creating a dropshadow for UITableView

查看:177
本文介绍了为UITableView创建一个阴影效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人请解释如何创建一个或两个像素阴影只在最后一个单元格(换句话说,我不想在整个tableview,只是底部单元格的阴影。我在说:

Would somebody please explain how to create a one or two pixel drop shadow ONLY on the the very last cell (in other words, I don't want a shadow around the entire tableview, just the bottom cell. An image of what I'm talking about:

推荐答案

解决。使用下面的代码在 UITableViewCell 。使它看起来像是从页面中略微提升:)

Solved. Use the following code to produce a very nice, subtle shadow to the bottom of your UITableViewCell. Makes it look like it's raised slightly out of the page :)

UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(3, 49, cell.frame.size.width-26, 3)];/// change size as you need.
        separatorLineView.backgroundColor = shadowColor;// you can also put image here
        UIBezierPath *roundedShadow = [UIBezierPath bezierPathWithRoundedRect:separatorLineView.bounds byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadii:CGSizeMake(8.0f, 8.0f)];
        CAShapeLayer *newSeparatorShape = [[CAShapeLayer alloc] init];
         [newSeparatorShape setPath:roundedShadow.CGPath];

        separatorLineView.layer.mask = newSeparatorShape;

        [cell.contentView addSubview:separatorLineView];

此外,不要忘记将它放在.m文件的顶部 #import< QuartzCore / QuartzCore.h>

Also, don't forget to put this at the top of your .m file #import <QuartzCore/QuartzCore.h>

这篇关于为UITableView创建一个阴影效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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