2017-05-18 14 views
0

enter image description hereテーブルビュー内でシャドウを作成する

イメージを使用しない場合は?

_t.layer.shadowColor = [UIColor blackColor].CGColor; 

    _t.layer.shadowOffset = CGSizeMake(-6, -6); 

    _t.layer.shadowOpacity = 1; 

    _t.clipsToBounds = false; 

これは影の外に作成される可能性があります。

+0

ステータスバーやタブバーの下に影を持つビューを追加し、これらのビューは、あなたのtableViewを超えています。 [statusBar - shadowView - tableView] – tomfriwel

答えて

1

ステータスバーまたはタブバーの下の影付きのビューを追加します。これらのビューは、あなたのtableViewの上にあります。

CGFloat statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height; 
CGFloat tabBarHeight = self.tabBarController.tabBar.bounds.size.height; 

// status bar 
UIView *statusBarShadowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, statusBarHeight)]; 
statusBarShadowView.backgroundColor = [UIColor whiteColor]; 
[self.view addSubview:statusBarShadowView]; 

CAGradientLayer *gradientLayer0 = [CAGradientLayer layer]; 
gradientLayer0.frame = CGRectMake(0, statusBarHeight, self.view.bounds.size.width, 10); 
gradientLayer0.colors = @[(id)[UIColor colorWithRed:0.91 green:0.91 blue:0.91 alpha:0.7].CGColor, (id)[UIColor colorWithWhite:1 alpha:0.7].CGColor]; 
[statusBarShadowView.layer insertSublayer:gradientLayer0 atIndex:0]; 


// tab bar 
UIView *tabBarShadowView = [[UIView alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height - tabBarHeight, [UIScreen mainScreen].bounds.size.width, tabBarHeight)]; 
statusBarShadowView.backgroundColor = [UIColor whiteColor]; 
[self.view addSubview:tabBarShadowView]; 

CAGradientLayer *gradientLayer1 = [CAGradientLayer layer]; 
gradientLayer1.frame = CGRectMake(0, -10, self.view.bounds.size.width, 10); 
gradientLayer1.colors = @[(id)[UIColor colorWithWhite:1 alpha:0.7].CGColor, (id)[UIColor colorWithRed:0.91 green:0.91 blue:0.91 alpha:0.7].CGColor]; 
[tabBarShadowView.layer insertSublayer:gradientLayer1 atIndex:0]; 

+0

テーブルビューのフレームが変更されるので、単にtableviewに追加できますか? –

+0

あなたはそうすることができますが、影はテーブルビューでスクロールし、固定された影の位置にいくつかの作業を行います。 – tomfriwel

+0

これはレイヤーなので、テーブルビューに置くことができます。そしてテーブルビューと共に移動します。 –

関連する問題