在tableview中创建阴影

时间:2017-05-18 03:29:06

标签: ios objective-c uitableview

enter image description here

如果没有使用图片?

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

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

    _t.layer.shadowOpacity = 1;

    _t.clipsToBounds = false;

这可以创造外部阴影。

1 个答案:

答案 0 :(得分: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];

相关问题