2012-02-14 51 views
1

我只有幾行的tableview。所以,而不是顯示一堆空白我添加一個空白的UIView到tableview.footer。不過,我希望最後一個單元在UIView上投下陰影。我將如何實現這一目標?這是我目前的代碼。iOS:表格單元格footer dropshadow

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    UIView *emptyView = [[UIView alloc] initWithFrame:CGRectZero]; 
    CALayer *layer = [emptyView layer]; 
    [layer setShadowOffset:CGSizeMake(0, 1)]; 
    [layer setShadowColor:[[UIColor darkGrayColor] CGColor]]; 
    [layer setShadowRadius:8.0]; 
    [layer setShadowOpacity:0.8]; 
    self.tableView.tableFooterView = emptyView; 
} 

編輯: 它增加了UIView到頁腳,但沒有創造陰影效果。我不確定這個圖層是否是這種類型的最佳方法,甚至是正確的。

回答

0

我結束了使用

shadowBackgroundView.layer.shadowOpacity = 0.3; 
shadowBackgroundView.layer.shadowRadius = 2; 
shadowBackgroundView.layer.shadowColor = [[UIColor blackColor] CGColor]; 
shadowBackgroundView.layer.shadowOffset = CGSizeMake(0.0, 1.0); 
CGPathRef shadowPath = [UIBezierPath bezierPathWithRoundedRect: shadowBackgroundView.bounds 
                 byRoundingCorners: UIRectCornerAllCorners 
                   cornerRadii: CGSizeMake(PageCellBackgroundRadius, PageCellBackgroundRadius)].CGPath; 
shadowBackgroundView.layer.shadowPath = shadowPath; 
shadowBackgroundView.layer.shouldRasterize = YES; 

[self addSubview: shadowBackgroundView]; 
0

這可能是因爲您將框架設置爲CGRectZero。

零矩形等價於CGRectMake(0,0,0,0)。

零矩形(x = 0,y = 0,寬度= 0,高度= 0)的陰影根本不會顯示。

嘗試給它一個適當的框架大小,你會看到不同。

退房此爲參考,以及:https://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CGGeometry/Reference/reference.html

+0

沒有用'CGRectMake差異可言(0,0,100,100 )' – Bot 2012-02-14 23:00:21

0

cellForRowAtIndexPath:功能:

// drop shadow 
cell.layer.shadowOpacity = 1.0; 
cell.layer.shadowRadius = 1.7; 
cell.layer.shadowColor = [UIColor blackColor].CGColor; 
cell.layer.shadowOffset = CGSizeMake(0.0, 0.0);