一.ViewController.m中代碼程序員
// // ViewController.m // 啦啦 // // Created by 非凡程序員 on 15/6/9. // Copyright (c) 2015年 wzhen. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; _timer=[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(shijian:) userInfo:nil repeats:YES]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)shijian:(id)sender { NSDate *today=[NSDate date]; NSDateFormatter *format=[NSDateFormatter new]; [format setDateFormat:@"yyyy年MM月dd日 HH時mm分ss秒"]; [_nowtime setText:[format stringFromDate:today]]; [_ring setText:_nowtime.text]; if ([_nowtime.text compare:_settime.text]==NSOrderedDescending) { NSLog(@"timercount=%i",_timercount); if (_timercount>=30 && _timercount<=70) { [_ring setText:_nowtime.text]; [today dateByAddingTimeInterval:(1*1*60)]; [_settime setText:[format stringFromDate:today]]; _timercount++; } else{ [_ring setText:@"thanks終於響了"]; _timercount++; if (_timercount==80) { _timercount=0; } } } // if (timercount==10) { // [_ring setText:_nowtime.text]; // [today dateByAddingTimeInterval:(20)]; // [_settime setText:[format stringFromDate:today]]; //// [_timer invalidate]; //// NSTimer * p=[[NSTimer alloc]initWithFireDate:nil interval:20 target:nil selector:nil userInfo:nil repeats:YES]; //// [p setFireDate:today]; // } } - (IBAction)change:(id)sender { [_daxie setText:_yuanzhi.text.uppercaseString]; [_xiaoxie setText:_yuanzhi.text.lowercaseString]; NSString *temp=_yuanzhi.text.capitalizedString; NSString *final=[temp substringWithRange:NSMakeRange(0, [temp length]-1)]; final=[NSString stringWithFormat:@"%@%@",final,[[temp substringWithRange:NSMakeRange([temp length]-1, 1)]capitalizedString]]; [_shou setText:final]; [_huan setTitle:@"大小寫轉換" forState:UIControlStateNormal]; } @end
二.ViewController.h中代碼api
// // ViewController.h // 啦啦 // // Created by 非凡程序員 on 15/6/9. // Copyright (c) 2015年 wzhen. All rights reserved. // #import <UIKit/UIKit.h> @interface ViewController : UIViewController @property (assign, nonatomic) int timercount; @property (weak, nonatomic)NSTimer * timer; @property (weak, nonatomic) IBOutlet UITextField *ring; @property (weak, nonatomic) IBOutlet UITextField *settime; @property (weak, nonatomic) IBOutlet UILabel *nowtime; @property (weak, nonatomic) IBOutlet UIButton *huan; - (IBAction)shijian:(id)sender; - (IBAction)change:(id)sender; @property (weak, nonatomic) IBOutlet UITextField *yuanzhi; @property (weak, nonatomic) IBOutlet UITextField *daxie; @property (weak, nonatomic) IBOutlet UITextField *xiaoxie; @property (weak, nonatomic) IBOutlet UITextField *shou; @end