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