UITableViewにドロップシャドウを追加するためのサンプルアプリを作成しました。右のナビゲーションボタンをクリックすると、ドロップシャドウがテーブルに追加されます。問題は、画面に表示されているテーブルの部分にのみシャドウが追加されることです。上にスクロールする(そしてテーブルから離れる)か、下にスクロールして他のセルを表示しようとすると、影が表示されません。テーブルの高さ全体に影を設定するにはどうすればよいですか?可能であれば、上にスクロールしてテーブルから離れた場合にも影ができます(バウンス効果のため)。2つのスクリーンショットとコードのいずれかを添付します。
最初のスクリーンショットでは、下にスクロールして他のセルを表示し、2番目のスクリーンショットでは、デフォルトの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;
}