Henson Fang
Henson Fang

Reputation: 1207

Create shadow inside a tableview

enter image description here

If not using an image?

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

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

    _t.layer.shadowOpacity = 1;

    _t.clipsToBounds = false;

this can create outside shadow.

Upvotes: 0

Views: 62

Answers (1)

tomfriwel
tomfriwel

Reputation: 2635

Add view with shadow below status bar or tab bar, and these views are above your 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];

Upvotes: 1

Related Questions