zoukankan      html  css  js  c++  java
  • Swift 渐变色

    示例:

    //    设置渐变颜色方向
            //    gradientLayer.startPoint = CGPointMake(0, 0); // 左上
            //    gradientLayer.endPoint = CGPointMake(0, 1); // 左下
            //    gradientLayer.endPoint = CGPointMake(1, 0); // 右上
            //    gradientLayer.endPoint = CGPointMake(1, 1); // 右下
    
            if (indexPath.row==0) {
                
                //渐变设置
                let colorOne:UIColor = UIColor.init().UIColorFromRGB(color_vaule: "#1EB0FF")
                let colorTwo:UIColor = UIColor.init().UIColorFromRGB(color_vaule: "#035CD8")
           
                let colors = [colorOne.cgColor,colorTwo.cgColor];
                let gradient:CAGradientLayer = CAGradientLayer.init();
                //设置开始和结束位置(通过开始和结束位置来控制渐变的方向)
                gradient.startPoint = CGPoint.init(x: 0, y: 0.5)
                gradient.endPoint = CGPoint.init(x: 1, y: 0.5)
                gradient.colors = colors;
                gradient.frame = mycell.bounds;
                gradient.cornerRadius=20;
                mycell.contentView.layer.insertSublayer(gradient, at: 0)
            
            }
            else if (indexPath.row==1){
            
                //渐变设置
                 let colorOne:UIColor = UIColor.init().UIColorFromRGB(color_vaule: "#FFA156")
                 let colorTwo:UIColor = UIColor.init().UIColorFromRGB(color_vaule: "#FF722D")
            
                 let colors = [colorOne.cgColor,colorTwo.cgColor];
                 let gradient:CAGradientLayer = CAGradientLayer.init();
                 //设置开始和结束位置(通过开始和结束位置来控制渐变的方向)
                 gradient.startPoint = CGPoint.init(x: 0, y: 0.5)
                 gradient.endPoint = CGPoint.init(x: 1, y: 0.5)
                 gradient.colors = colors;
                 gradient.frame = mycell.bounds;
                gradient.cornerRadius=20;
                 mycell.contentView.layer.insertSublayer(gradient, at: 0)
                
                
            }
            else{
           
                let colorOne:UIColor = UIColor.init().UIColorFromRGB(color_vaule: "#BCEE4F")
                 let colorTwo:UIColor = UIColor.init().UIColorFromRGB(color_vaule: "#63CB52")
            
                 let colors = [colorOne.cgColor,colorTwo.cgColor];
                 let gradient:CAGradientLayer = CAGradientLayer.init();
                 //设置开始和结束位置(通过开始和结束位置来控制渐变的方向)
                 gradient.startPoint = CGPoint.init(x: 0, y: 0.5)
                 gradient.endPoint = CGPoint.init(x: 1, y: 0.5)
                 gradient.colors = colors;
                 gradient.frame = mycell.bounds;
                gradient.cornerRadius=20;
                 mycell.contentView.layer.insertSublayer(gradient, at: 0)
            }
    
    此文仅为鄙人学习笔记之用,朋友你来了,如有不明白或者建议又或者想给我指点一二,请私信我。liuw_flexi@163.com/QQ群:582039935. 我的gitHub: (学习代码都在gitHub) https://github.com/nwgdegitHub/
  • 相关阅读:
    iframe自动适应高度
    php正则过滤html标签、空格、换行符的代码,提取图片
    destoon使用中的一些心得
    Fiddler 过滤 css,图片等请求url 正则表达式
    不用递归实现无限分类数据的树形格式化
    PHP定时执行任务的实现
    Discuz! X3.1去除内置门户导航/portal.php尾巴的方法
    discuzx完全自定义设计模板门户首页,栏目,专题模板方法
    Apache环境.htaccess伪静态301跳转(www与不带www)
    15万甚至30万以内的SUV值不值得买?
  • 原文地址:https://www.cnblogs.com/liuw-flexi/p/12923378.html
Copyright © 2011-2022 走看看