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

  • 相关阅读:
    8.使用axios实现登录功能
    7.django配置跨域并开发测试接口
    9.Vue组件
    2.初始化项目结构
    1.Django基础
    团队冲刺——第七天
    团队冲刺——第六天
    十天冲刺——第五天
    十天冲刺——第四天
    十天冲刺——第三天
  • 原文地址:https://www.cnblogs.com/hsxblog/p/4927362.html
Copyright © 2011-2022 走看看