iOS 聊天内容滚动渐隐效果

// 添加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;
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容