zoukankan      html  css  js  c++  java
  • Color, 霓虹灯效果练习

    #import "RootViewController.h"

    @interface RootViewController (){

        CAGradientLayer *gradientLayer;

        NSTimer *timer;

    }

    @end

    @implementation RootViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage   imageNamed:@"美女图.jpg"]];

        imageView.frame = self.view.bounds;

        gradientLayer = [CAGradientLayer layer];

        gradientLayer.frame = imageView.bounds;

        [imageView.layer addSublayer:gradientLayer];

        [self.view addSubview:imageView];

        [imageView release];

        //设置颜色渐变方向

        gradientLayer.startPoint = CGPointMake(0, 0);

        gradientLayer.endPoint = CGPointMake(0, 1);

        //设定颜色组

        gradientLayer.colors = @[(__bridge id)[UIColor clearColor].CGColor, (__bridge id)[UIColor purpleColor].CGColor];//((__bridge id)把颜色转化为一个对象)

        //设定颜色分割点

        gradientLayer.locations = @[@(0.5f), @(1.0f)];

        //设置时间定时器

        timer = [NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:@selector(TimeChange) userInfo:nil repeats:YES];

        

        

    }

    - (void)TimeChange{

        //定时随机颜色

        gradientLayer.colors = @[(id)[[UIColor clearColor] CGColor], (id)[UIColor colorWithRed:arc4random() % 256 / 255. green:arc4random() % 256 / 255. blue:arc4random() % 256 / 255. alpha:1.0].CGColor];

        gradientLayer.locations = @[@(arc4random() % 10 / 10.0f), @(1.0f)];

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    @end

  • 相关阅读:
    Openrasp源码分析
    feifeicms后台任意文件读取
    python之迭代器和生成器
    java之导入excel
    jquery单击事件的写法
    java之高效操作文件
    多条件搜索优化sql
    java之代码复用
    java之接口文档规范
    eclipse之常用快捷键
  • 原文地址:https://www.cnblogs.com/hsxblog/p/4927362.html
Copyright © 2011-2022 走看看