// 添加tableViewBG_View到self.view上
UIView *tableViewBG_View = [[UIView alloc] initWithFrame:tableViewBGRect];
[self.view addSubview:tableViewBG_View];
// tableView添加到tableViewBG_View上
UITableView *tableView = [[UITableView alloc] initWithFrame:tableViewBG_View.bounds style:UITableViewStylePlain];
[tableViewBG_View addSubview:tableView];
tableView.backgroundColor = [UIColor clearColor];
// 设置顶部渐隐层
CAGradientLayer *gradientLayer = [[CAGradientLayer alloc] init];
gradientLayer = [CAGradientLayer layer];
gradientLayer.startPoint = CGPointMake(0, 0); //渐变色起始位置
gradientLayer.endPoint = CGPointMake(0, 0.1); //渐变色终止位置
gradientLayer.colors = @[(__bridge id)[UIColor.clearColor colorWithAlphaComponent:0].CGColor, (__bridge id)
[UIColor.clearColor colorWithAlphaComponent:1.0].CGColor];
gradientLayer.locations = @[@(0), @(1.0)]; // 对应colors的alpha值
gradientLayer.frame = tableViewBG_View.bounds;
tableViewBG_View.layer.mask = gradientLayer;
网友评论