设为首页 加入收藏

TOP

简单的秒表定时器(一)
2017-10-13 10:09:47 】 浏览:1876
Tags:简单 秒表 定时器

 简单的秒表定时器

思路:

1.分别添加秒表中的上部分,样式如 00 :00 : 00 . 00,分别表示时,分,秒,毫秒一共用7个labe实现

2.设置按钮,分别是开始,停止,复位

3,通过字符串转换成数字,和数字转换成字符串来进行秒表的设计

 

  1 #import "ViewController.h"
  2 
  3 #import "UIView+FrameExtension.h"
  4 
  7 #define kDeviceWidth [UIScreen mainScreen].bounds.size.width
  8 
  9 #define kDeviceHeight [UIScreen mainScreen].bounds.size.height
 10 
 13 @interface ViewController (){
 14 
 15     UILabel *_lbl1;
 16 
 17     UILabel *_lbl2;
 18 
 19     UILabel *_lbl3;
 20 
 21     UILabel *_lbl4;

 25     NSTimer *_timer;
 26 
 27     BOOL    _isRunning;
 28 
 29 }
 33 @end
 34 
 37 @implementation ViewController
 38 
 41 - (void)viewDidLoad {
 42 
 43     [super viewDidLoad];
 44 
 47     [self createLabel];     //创建7个标签
 48 
 49     [self createTimer];     //创建1个定时器
 50 
 51     [self createButton];    //创建3个按
 52 
 53 }
 54 
 57 -(void)createLabel{

 61     UILabel *lbl1 = [[UILabel alloc]initWithFrame:CGRectMake(90, 200, 30, 40)];
 62 
 63     lbl1.text = @"00";
 64 
 65     lbl1.textColor = [UIColor redColor];
 66 
 67     [self.view addSubview:lbl1];
 68 
 69     _lbl1 = lbl1;
 70 
 73     UILabel *lbl11 = [[UILabel alloc]initWithFrame:CGRectMake(lbl1.right, lbl1.y, 10, lbl1.height)];
 74 
 75     lbl11.text = @":";
 76 
 77     lbl11.textColor = [UIColor redColor];
 78 
 79     [self.view addSubview:lbl11];
 80 
 83      UILabel *lbl2 = [[UILabel alloc]initWithFrame:CGRectMake(lbl11.right, lbl1.y, lbl1.width, lbl1.height)];
 84 
 85     lbl2.text = @"00";
 86 
 87     lbl2.textColor = [UIColor redColor];
 88 
 89     [self.view addSubview:lbl2];
 90 
 91     _lbl2 = lbl2;
 92 
 95     UILabel *lbl22 = [[UILabel alloc]initWithFrame:CGRectMake(lbl2.right, lbl1.y, lbl11.width, lbl1.height)];
 96 
 97     lbl22.text = @":";
 98 
 99     lbl22.textColor = [UIColor redColor];
100 
101     [self.view addSubview:lbl22];
102 
103     UILabel *lbl3 = [[UILabel alloc]initWithFrame:CGRectMake(lbl22.right, lbl1.y, lbl1.width, lbl1.height)];
104 
105     lbl3.text = @"00";
106 
107     lbl3.textColor = [UIColor redColor];
108 
109     [self.view addSubview:lbl3];
110 
111     _lbl3 = lbl3;
112 
115     UILabel *lbl33 = [[UILabel alloc]initWithFrame:CGRectMake(lbl3.right, lbl1.y, lbl11.width, lbl1.height)];
116 
117     lbl33.text = @".";
118 
119     lbl33.textColor = [UIColor redColor];
120 
121     [self.view addSubview:lbl33]; 
122 
123     UILabel *lbl4 = [[UILabel alloc]initWithFrame:CGRectMake(lbl33.right, lbl1.y, lbl1.width, lbl1.height)];
124 
125     lbl4.text = @"00";
126 
127     lbl4.textColor = [UIColor redColor];
128 
129     [self.view addSubview:lbl4];
130 
131     _lbl4 = lbl4;
132 
137 }

141 -(void)createButton{
142  
146 
147     UIButton *btn1 = [[UIButton alloc]initWithFrame:CGRectMake(70, _lbl1.bottom+20, 60, 40)];
148 
149     [btn1 setTitle:@"开始" forState:UIControlStateNormal];
150 
151     [self.view addSubview:btn1];
152 
153     [btn1 setBackgroundImage:[UIImage imageNamed:@"logoff_btn_s"] forState:UIControlStateNormal];
154 
155     [btn1 setBackgroundImage:[UIImage imageNamed:@"submit_discussion_n"] forState:UIControlStateHighlighted];
156 
157     [btn1 addTarget:self action:@selector(start ) forControlEvents:UIControlEventTouchUpInside];
158 
163     UIButton *btn2 = [[UIButton alloc]initWithFrame:CGRectMake(btn1.right+10, btn1.y, btn1.
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇简单的秒表定时器 下一篇IOS开发之音频--录音

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目