IOS UITextField使用

七色彩虹小项目总结

本项目 从构思到完成 用时不长,主要是在思考功能化的实现,如初始化视图,改变视图状

态,主要就是这两个函数。初始化里面,是对各个UIView的定义,布局,设置颜色等初始

化工作。其中主要用到的是UIView这个类,她是视图的基类,
 //红色视图
    UIView *redView=[[UIView alloc] initWithFrame:CGRectMake(20, 20, 280, 280)];
    redView.backgroundColor=[UIColor redColor];
    redView.tag=1;
    [self.view addSubview:redView];
    [redView release];

如上所示,初始化一个View,设置其背景颜色,标志,向其中添加视图,等等。

第二个函数就是完成,主要功能,视图的状态改变。其中有一个NSArray 用来保存颜色值,一个NSMutableArray 用来保存各个视图对象。

以下为关键代码

    for (int i=0; i<7-currentColor; i++) {
        [[viewArray objectAtIndex:i] setBackgroundColor:[colorArray objectAtIndex:i+currentColor]];
    }
    
    for (int i=6-currentColor,j=0; i<7;j++,i++) {
        [[viewArray objectAtIndex:i] setBackgroundColor:[colorArray objectAtIndex:j]];
    }

最后用到一个定时器功能,需要循环调用改变视图状态的函数。


NSTimer 其用法如下

 
    NSTimer *timer=[NSTimer  timerWithTimeInterval:0.5 target:self selector:@selector(showChangeView:) userInfo:nil repeats:YES];
    NSRunLoop *runloop=[NSRunLoop currentRunLoop];
    [runloop addTimer:timer forMode:NSDefaultRunLoopMode];
    
//    [timer fire];
    
    
    
    NSTimer *time2=[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(showChangeView:) userInfo:nil repeats:YES];
    [time2 fire];


通过运行程序发现NSTimer的各个初始化方法的差异,如上可见,有的是直接加入到循环队列里,一个必须手添加,其实看单词 也能看出来,以后要多总结,嘿嘿;

Creating a Timer
        + scheduledTimerWithTimeInterval:invocation:repeats:
        + scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:
        + timerWithTimeInterval:invocation:repeats:
        + timerWithTimeInterval:target:selector:userInfo:repeats:
        – initWithFireDate:interval:target:selector:userInfo:repeats:


Firing a Timer
        – fire  //开始一个定时器
Stopping a Timer
        – invalidate //取消一个定时器
Information About a Timer
        – isValid
        
        – fireDate //Return Value
        The date at which the receiver will fire. If the timer is no longer valid, this method returns the last date at which the timer fired.
        
        – setFireDate:
        Parameters
        date
        The new date at which to fire the receiver. If the new date is in the past, this method sets the fire time to the current time.
        
        – timeInterval
        Return Value
        The receiver’s time interval. If the receiver is a non-repeating timer, returns 0 (even if a time interval was set).
        
        – userInfo
Return Value
The receiver's userInfo object.

插曲:最后又给这个项目加了一点动画,是自己前几天刚从网上学的,虽然还没有
理解其原理,但感觉可以用在这里,实现后发现,果然效果不错。

项目总结:在这个小项目中,我学到了,好多东西,首先,拿到一问题,不要急着
下手去解决,先把问题分解,分解成各个模块,然后再一个一个去解决。这样很重
要,可以把问题细化,复杂问题简单化,然后各个击破,这样就显得程序结构清
楚,编程思路明朗,维护起来比较容易。好的编程模式,可以节省好多力气,以后
要多多总结,多多实践,好了这个项目先做到这里吧。牵涉到的知识点,不是很懂
的,会很快学习然后慢慢充实自己的知识结构体系。




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值