iOS 渐变色和毛玻璃效果

使用CAGradientLayer实现渐变色效果

#define kRGBColor(r, g, b, a)  [UIColor colorWithRed:(r) / 255.0 green:(g) / 255.0 blue:(b) / 255.0 alpha: a]

// 创建 CAGradientLayer 对象
CAGradientLayer *gradientLayer = [CAGradientLayer layer];

// 设置 gradientLayer 的 Frame
gradientLayer.frame = self.view.bounds;

// 创建渐变色数组,需要转换为CGColor颜色
gradientLayer.colors = @[(id)[UIColor whiteColor].CGColor,(id)kRGBColor(30, 144, 255, 1).CGColor];

// 设置颜色分割点
gradientLayer.locations = @[@(0.1f) ,@(1)];

// 设置渐变颜色方向,左上点为(0,0), 右下点为(1,1)
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(0, 1);

// 添加渐变色到创建的 UIView 上
[self.view.layer addSublayer:gradientLayer];

毛玻璃效果

 // 创建imageView    
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 240, self.view.bounds.size.width, 200)];       
[imageView setImage:[UIImage imageNamed:@"cr7.jpg"]];  
[self.view addSubview:imageView];      

// blur效果       
UIVisualEffectView *visual = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];      
visual.frame = imageView.bounds;       
visual.alpha = 0.8f;   
[imageView addSubview:visual];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,200评论 4 61
  • cuiymdeMacBook-Pro:webapps cuiym$ brew install activemq 1...
    回声2016阅读 1,244评论 0 0
  • TCP:Transmission Control Protocol,传输控制协议 IP:Internet Prot...
    踩在浪花上00阅读 451评论 0 0
  • 我的这段感情 开始就很无奇 我表白 她接受 从开始就像一杯白开水 她说答应的原因是 她不烦我 可以和我聊天很久 本...
    啊哈嘿呀阅读 235评论 0 0
  • Cmake 入门 前言 CMake是一个比make更高级的编译配置工具,它可以根据不同平台、不同的编译器,生成相应...
    渝潼不肖生阅读 2,143评论 1 5