ゴールと現状を書き出し
次することを見つける
URU×2 の備忘録: iPhoneアプリ開発 トイレでも見やすい時計アプリ
の続き
しばらく滞っていた時計アプリ作り
どこから手に付けたら良いか分からない状態に・・・
■ 目的を把握しよう
目的は、
トイレ時に時間を確認するため
アプリの形は、
大きめのデジタル時計で、秒数の時間帯で色が変化
■ 現状把握しよう!!
xcodeでRunを押して
アプリの動きを確認すると
こんな感じで
一番下の秒数が動いていました。
コードをみると
● ViewController.h
#import
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *myLabel01;
@property (weak, nonatomic) IBOutlet UILabel *myLabel2;
@property (weak, nonatomic) IBOutlet UILabel *myLabel3;
@property (weak, nonatomic) IBOutlet UILabel *myLabel4;
@property (weak, nonatomic) IBOutlet UILabel *myLabel5;
@property (weak, nonatomic) IBOutlet UILabel *myLabel6;
@end
● ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[NSTimer scheduledTimerWithTimeInterval:0.5f
target:self
selector:@selector(nowtime:)
userInfo:nil
repeats:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)nowtime:(NSTimer *)timer {
NSDate *now = [NSDate date];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSUInteger flags;
NSDateComponents *comps;
// 年・月・日を取得
flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit |NSHourCalendarUnit |NSMinuteCalendarUnit |NSSecondCalendarUnit;
comps = [calendar components:flags fromDate:now];
NSInteger year = comps.year;
NSInteger month = comps.month;
NSInteger day = comps.day;
NSInteger hour = comps.hour;
NSInteger minute = comps.minute;
NSInteger second = comps.second;
_myLabel01.text = [NSString stringWithFormat: @"%d", year];
_myLabel2.text = [NSString stringWithFormat: @"%d", month];
_myLabel3.text = [NSString stringWithFormat: @"%d", day];
_myLabel4.text = [NSString stringWithFormat: @"%d", hour];
_myLabel5.text = [NSString stringWithFormat: @"%d", minute];
_myLabel6.text = [NSString stringWithFormat: @"%d", second];
}
@end
まとめると
起動時、viewDidLoadで
TimerIntervalが動いて0.5秒ごとに
nowtimeメソッド(時刻を表示する)が呼び出されています
時刻を取得表示は
NSDate , NSCalenderを使い月や秒単位ごとに取得表示
■ 次ぎする事を考えよう
前回のスケッチを元に、次ぎする事を考えると
・格好良い時計のUIを作る
□ 見やすいアプリのUIを集める
□ 数字、背景に応用する
・case文など使用して、その時刻の数字になったら、指定の数字の画像を表示させる
□ Xcodeでcase文の書き方を調べる
0 件のコメント:
コメントを投稿