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

  • 相关阅读:
    前端开发 Vue -3axios
    前端开发 Vue -2npm
    前端开发 Vue -1windows环境搭建Vue Node开发环境
    前端开发 Vue -0前言
    linux
    java 框架-缓冲-Redis 2Jedis操作
    java 框架-缓冲-Redis 1概述
    微软银光 silverlight简介
    bs模型与cs模型
    安装vs2010
  • 原文地址:https://www.cnblogs.com/hsxblog/p/4927362.html
Copyright © 2011-2022 走看看