先上效果图

#import "CHViewController.h"
@interface CHViewController ()
{
    int i;
    int j;
}
@property NSInteger isStart;
@property (nonatomic,retain) NSMutableArray *viewArray;
@property (nonatomic,retain) UIView *neonView;
@property (nonatomic,retain)   NSTimer *timer;

@end

static inline CGRect rectWithScale(CGRect rect,CGFloat scale)
{
    rect.size.width+=scale;
    rect.size.height+=scale;
    return rect;
}

@implementation CHViewController
-(UIColor *)getRandomColor:(NSInteger)max add:(NSInteger)num
{
    CGFloat r,g,b;
    r=arc4random()%max +num;
    g=arc4random()%max +num;
    b=arc4random()%max +num;
    return [UIColor colorWithRed:r/225.0 green:g/225.0 blue:b/225.0 alpha:1.0f];
}

- (void)viewDidLoad
{
    i=0;//视图下标
    j=0;
        _isStart=0;
    ///////////背景色
    UIView *backGround=[[UIView alloc]initWithFrame:self.view.bounds];
    backGround.backgroundColor= [self getRandomColor:31 add:95];
    [self.view addSubview:backGround];
    //////////标题栏视图设置
    UIView *titleView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 20)];
    titleView.backgroundColor=[UIColor colorWithRed:33/255.0 green:33/255.0  blue:33/255.0  alpha:0.5];
    [backGround addSubview:titleView];
    //////////按钮设置
   UIButton *button= [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame=CGRectMake(20, backGround.bounds.size.height-130, 280, 40);
    [button setTitle:@"Start" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    button.backgroundColor=[UIColor whiteColor];
    [backGround addSubview:button];
    [button addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
    
    ///////////////霓虹灯框视图设置
    _neonView=[[UIView alloc]initWithFrame:CGRectMake(50, 60, 220, 220)];
    _neonView.backgroundColor=[UIColor whiteColor];
    [backGround addSubview:_neonView];
 
    //////////////zoom视图入数组
    _viewArray=[[NSMutableArray alloc]init];
    for (int index=0; index<1000; index++) {
        UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0,0,5,5)];
          CGPoint point=CGPointMake(CGRectGetMidX(_neonView.bounds), CGRectGetMidY(_neonView.bounds));
        view.center=point;
            view.bounds=rectWithScale(view.bounds, 4.3f);
            view.backgroundColor=[self getRandomColor:256 add:0];
        [_viewArray addObject:view];
    }
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

-(void)onClick:(UIButton *)button
{
    i=0;

if (_isStart==0) {
_timer=[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(showTime:) userInfo:nil repeats:YES];
        _isStart=1;
        [button setTitle:@"Stop" forState:UIControlStateNormal];
        
    }
    else
    {
        _isStart=0;
        [button setTitle:@"Start" forState:UIControlStateNormal];
        [_timer invalidate];
    }
    }

-(void)showTime:(NSTimer *)timer
{
 
   for (j=0; j<i; j++) {
     if (((UIView*)_viewArray[j]).bounds.size.height>=CGRectGetHeight(_neonView.bounds)) {
        ((UIView*)_viewArray[j]).bounds=CGRectMake(0,0,5,5);
        ((UIView*)_viewArray[j]).center=CGPointMake(CGRectGetMidX(_neonView.bounds), CGRectGetMidY(_neonView.bounds));
        [((UIView*)_viewArray[j]) removeFromSuperview];
         //[_neonView addSubview:_viewArray[j]];
        
    }
        ((UIView*)_viewArray[j]).bounds=rectWithScale(((UIView*)_viewArray[j]).bounds, 5.0f);
       // ((UIView*)_viewArray[j]).backgroundColor=[self getRandomColor:256 add:0];
        if (i<1000)
       [_neonView addSubview:_viewArray[j]];
      
   }
    if (i<1000) {
         i++;
    }
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
  /*  UIView *view=    }*/

}

@end

IOS 作业项目(3) 霓虹灯效果的更多相关文章

  1. IOS 作业项目(4)步步完成 画图 程序(中)

    一,承接上文,继续本文  [UIButton buttonWithType:UIButtonTypeRoundedRect]; 如此声明的按钮才会有点击闪动的效果!如果直接frame方式声明就不会有. ...

  2. IOS 作业项目(2) 画图(保存,撤销,笔粗细设定功能)

    先上效果图

  3. IOS 作业项目(1) 关灯游戏 (百行代码搞定)

    1,准备工作,既然要开关灯,就需要确定灯的灯的颜色状态 首先想到的是扩展UIColor

  4. IOS 作业项目 TableView两个section中cell置顶功能实现

    点击cell会置顶,其他的下移

  5. IOS 作业项目(4)步步完成 画图 程序(问题处理)终结

    一,解决换色程序崩溃问题 程序崩溃是因为颜色的内存被释放,添加如下类的内容即可 @implementation TuyaPath - (id)init { self = [super init]; i ...

  6. IOS 作业项目(4)步步完成 画图 程序(剧终)

    // //  CHViewController.m //  SuperDrawingSample // //  Created by JaikenLI on 13-11-21. //  Copyrig ...

  7. IOS 作业项目(4)步步完成 画图 程序(中续)

    一,程序布局整理 前言://1,程序启动//2,程序流程框架//3,程序界面一致//4,程序界面功能, //这里只做页面的固定功能, //在首次创建界面时,我们会指定好固定事件触发前的固定方法 //至 ...

  8. IOS 作业项目(4)步步完成 画图 程序(上)

    先上流程图

  9. GitHub Android 最火开源项目Top20 GitHub 上的开源项目不胜枚举,越来越多的开源项目正在迁移到GitHub平台上。基于不要重复造轮子的原则,了解当下比较流行的Android与iOS开源项目很是必要。利用这些项目,有时能够让你达到事半功倍的效果。

    1. ActionBarSherlock(推荐) ActionBarSherlock应该算得上是GitHub上最火的Android开源项目了,它是一个独立的库,通过一个API和主题,开发者就可以很方便 ...

随机推荐

  1. nyoj------布线问题(kruscal+求最小值)

    布线问题 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 南阳理工学院要进行用电线路改造,现在校长要求设计师设计出一种布线方式,该布线方式需要满足以下条件:1.把所有 ...

  2. IOS开发设计思路

    我在做 iOS 开发的时候,发现自己在写程序的时候,常常处于两种状态的切换,我把这两种状态称为软件开发的上帝模式与农民模式.我先给大家介绍一下这两种模式的特点. 上帝模式 处于上帝模式时,我需要构思整 ...

  3. Java 集合系列 06 Stack详细介绍(源码解析)和使用示例

    java 集合系列目录: Java 集合系列 01 总体框架 Java 集合系列 02 Collection架构 Java 集合系列 03 ArrayList详细介绍(源码解析)和使用示例 Java ...

  4. Python输出内容的三种方式:print输出 python脚本执行 linux直接执行

    1.  在linux中安装python后,在linux命令行中输入python即可切换到Python命令行下 退出python命令行的命令: 老版本:ctrl+D 新版本:quit();或exit() ...

  5. word linkage 选择合适的聚类个数matlab code

    clear load fisheriris X = meas; m = size(X,2); % load machine % load census % % X = meas; % X=X(1:20 ...

  6. MySQL索引实现

    摘自:http://blog.codinglabs.org/articles/theory-of-mysql-index.html 在MySQL中,索引属于存储引擎级别的概念,不同存储引擎对索引的实现 ...

  7. Oracle导入excel数据方法汇总[转]

    摘要:在程序编制过程和数据汇总交换过程中,经常会碰到需要将其他人员在office办公环境下编制的文件数据内容导入oracle中的情况.目前程序开发者经常使用的方法有如下几种:1,使用oracle提供的 ...

  8. linux web php 安全相关设置

    1 隐藏apache 或者 nginx的版本号 2 隐藏php的版本号 3 php 程序做好基本的防注入 xss之类的攻击 4 禁用PHP一些危险的函数 比如 phpinfo.system之类的 5 ...

  9. JSP 服务器响应

    Response响应对象主要将JSP容器处理后的结果传回到客户端.可以通过response变量设置HTTP的状态和向客户端发送数据,如Cookie.HTTP文件头信息等. 一个典型的响应看起来就像下面 ...

  10. hadoop版本比较 [转]

    由于Hadoop版本混乱多变,因此,Hadoop的版本选择问题一直令很多初级用户苦恼.本文总结了Apache Hadoop和Cloudera Hadoop的版本衍化过程,并给出了选择Hadoop版本的 ...