码迷,mamicode.com
首页 > 其他好文 > 详细

Color, 霓虹灯效果练习

时间:2015-11-01 11:26:58      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:

#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

 

Color, 霓虹灯效果练习

标签:

原文地址:http://www.cnblogs.com/hsxblog/p/4927362.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!