iphone学习之旅之实例:LED电子时钟
2009-09-06 00:00:00 来源:WEB开发网Objective-c代码
//
// LEDClockViewController.h
// LEDClock
//
// Created by blessdyb on 09-9-5.
// Copyright mobroad.com 2009. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface LEDClockViewController : UIViewController {
IBOutlet UILabel *timerLabel;
}
@property (nonatomic, retain) UILabel *timerLabel;
-(void) interval;
@end
下面进入控制器类的实现文件中对刚才的定义进行实现,双击LEDClockViewController.m,我们首先需要设置整个程序视图加载时时钟显示标签的字体,大小及初始化文本。这样,在计时器开始运行后,我们只需要每过一秒种改变显示标签的文本值就可以了。
Objective-c代码
//
// LEDClockViewController.m
// LEDClock
//
// Created by blessdyb on 09-9-5.
// Copyright mobroad.com 2009. All rights reserved.
//
#import "LEDClockViewController.h"
@implementation LEDClockViewController
@synthesize timerLabel;
-(void) interval{
NSUInteger unitFlags=NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSCalendar *calendar=[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *date=[NSDate date];
NSDateComponents *now=[calendar components:unitFlags fromDate:date];
int hour=[now hour];
int minute=[now minute];
int second=[now second];
[timerLabel setText:[NSString stringWithFormat:@"%02d:%02d:%02d",hour,minute,second]];
[calendar release];
}
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[timerLabel setFont:[UIFont fontWithName:@"DBLCDTempBlack" size:50.0]];
[timerLabel setText:@"电子时钟"];
[super viewDidLoad];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
return YES;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[timerLabel release];
[super dealloc];
}
@end
- ››iphone图片拉伸的几种方法
- ››iphone正则表达式的简单使用
- ››iPhone开发Unresolved Symbols CAKeyframeAnimati...
- ››IPhone开发-“此证书是由未知颁发机构签名”解决方...
- ››IPhone开发-整合私钥和证书,生成.p12文件
- ››iPhone应用开发-UIPickerView选取器详解
- ››iphone 获取屏幕的宽度和高度
- ››iPhone读取工程包中的二进制文件
- ››iPhone新手机 不挂YouTube APP
- ››iPhone 获取指定格式的时间和日期
- ››iPhone版PPS走进生活 观赏体验媲美PC版
- ››iPhone两种不同的应用程序:两种方法的哲学思想
更多精彩
赞助商链接