美文网首页
iOS 聊天内容滚动渐隐效果

iOS 聊天内容滚动渐隐效果

作者: 山杨 | 来源:发表于2021-05-15 10:55 被阅读0次
    // 添加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;
    

    相关文章

      网友评论

          本文标题:iOS 聊天内容滚动渐隐效果

          本文链接:https://www.haomeiwen.com/subject/yeuhjltx.html