CGColorRef darkColor = [[UIColor blackColor] colorWithAlphaComponent:.5f].CGColor;
CGColorRef lightColor = [UIColor clearColor].CGColor;
//Footer shadow
UIView *footerShadow = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 10)];
CAGradientLayer *bottomShadow = [[[CAGradientLayer alloc] init] autorelease];
bottomShadow.frame = CGRectMake(0,0, self.view.frame.size.width, 10);
bottomShadow.colors = [NSArray arrayWithObjects:(id)darkColor, (id)lightColor, nil];
footerShadow.alpha = 0.6;
[footerShadow.layer addSublayer:bottomShadow];
tb.tableFooterView = footerShadow;
//Header shadow
UIView *headerShadow = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 10)];
CAGradientLayer *topShadow = [[[CAGradientLayer alloc] init] autorelease];
topShadow.frame = CGRectMake(0, 0, self.view.frame.size.width, 10);
topShadow.colors = [NSArray arrayWithObjects:(id)lightColor, (id)darkColor, nil];
headerShadow.alpha = 0.3;
[headerShadow.layer addSublayer:topShadow];
tb.tableHeaderView = headerShadow;
tb.contentInset = UIEdgeInsetsMake(-10, 0, 0, 0);
The problem is that this work only for plain style UITableViews that do not use thetableHeaderViews and tableFooterViews for anything else. If the view is using those (which it definitely is in case it is a grouped UITableView) do the following:
//replace
self.tableView.tableHeaderView = headerShadow;
//with
[self.tableView insertSubview:headerShadow aboveSubview:self.tableView.tableHeaderView];
//and
self.tableView.tableFooterView = footerShadow;
//with
[self.tableView insertSubview:footerShadow belowSubview:self.tableView.tableFooterView];
分享到:
相关推荐
给 UITableview 添加阴影和变现,并且阴影渐变等样式的设计
UITableView、UITableView基本用法、UITableView详解,UITabelView常用方法
UITableView相关操作
UITableView Cache - UITableView 缓存
UITableView用来以表格的形式显示数据。关于UITableView,我们应该注意: (1)UITableView用来显示表格的可见部分,UITableViewCell用来显示表格的一行。 (2)UITableView并不负责存储表格中的数据,而是仅仅存储...
UITableView教材 IPHONE IPAD
UITableView通过重用单元格来达到节省内存的目的:通过为每个单元格指定一个重用标识符 reuseIdentifier 即指定了单元格的种类 以及当单元格滚出屏幕时 允许恢复单元格以便重用 对于不同种类的单元格使用不同的ID ...
IOS UITableView UIcollectionView 结合
UITableView 详细讲解
UITableView 缩进 附属视图 Cell Demo
UITableView 三级菜单
iOS UITableView查询及索引UISEARCHBAR
UITableView的SectionHeader的复用,UITableView的SectionHeader的复用
这是iPhone之UITableView入门的示例程序,具体参考: http://blog.csdn.net/htttw/article/details/7875462
UITableview处理键盘遮挡 没有实现控件复用导致的出现重复文本,以及部分bug。
UITableView的简单使用
UITableView 删除 Cell Demo Delete
UICollectionView,UITableView用法,UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
UITableView 简单例子,显示两个表区域,然后点击每行弹出一个提示框,有代码注释