`
zani
  • 浏览: 349848 次
  • 性别: Icon_minigender_1
  • 来自: 福州
社区版块
存档分类
最新评论

UITableView阴影

 
阅读更多

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];
 
分享到:
评论
1 楼 hhb19900618 2013-07-17  
你这个效果有渐变吗?

相关推荐

Global site tag (gtag.js) - Google Analytics