0
我创建了一个用于将投影添加到UITableView的示例应用程序。当您点击右侧导航按钮时,会将阴影添加到表格中。问题在于阴影仅添加到屏幕中可见的表格部分。如果我尝试向上滚动(并从桌面上移开)或向下滚动并查看其他单元格,则阴影不可见。我怎样才能为桌子的整个高度设置阴影?如果可能的话,如果我向上滚动并离开桌子(用于反弹效果),我也会有阴影。我附上了两个截图和代码。将投影添加到UITableView无法正常工作
在第一个屏幕截图中,向下滚动以查看其他单元格,在第二个屏幕上向上滚动以触发默认的UITableView反弹效果。
下面的代码:
- (void)printIt:(id)sender
{
[self.tableView.layer setShadowColor:[[UIColor orangeColor] CGColor]];
[self.tableView.layer setShadowOffset:CGSizeMake(0, 0)];
[self.tableView.layer setShadowRadius:15.0];
[self.tableView.layer setShadowOpacity:0.8];
[self.tableView.layer setMasksToBounds:NO];
self.tableView.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.tableView.layer.bounds].CGPath;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *testButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(printIt:)];
self.navigationItem.rightBarButtonItem = testButton;
[testButton release];
}
#pragma mark UITableView methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 105;
}
谢谢你。我没有想过。简单而干净。 – 2012-02-01 03:25:42