0

時間を別々の部分 (時間、分、秒) で表示するコードがあります。

- (void)viewDidLoad
{
    [self updateTime];

    [super viewDidLoad];

    hourFormatter = [[NSDateFormatter alloc] init];
    hourFormatter.dateFormat = @"HH";
    minuteFormatter = [[NSDateFormatter alloc] init];
    minuteFormatter.dateFormat = @"mm";
    secondFormatter = [[NSDateFormatter alloc] init];
    secondFormatter.dateFormat = @"ss";
}

- (void)updateTime {

    [updateTimer invalidate];
    updateTimer = nil;

    currentTime = [NSDate date];
    NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
    [timeFormatter setTimeStyle:NSDateFormatterMediumStyle];

    hourLabel.text = [hourFormatter stringFromDate: currentTime];
    minuteLabel.text = [minuteFormatter stringFromDate: currentTime];
    secondLabel.text = [secondFormatter stringFromDate: currentTime];

    updateTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(updateTime) userInfo:nil repeats:YES];
}

時間の経過とともに上昇する 3 つのバー (時間、分、秒) が必要です。この cydia ロック画面の微調整とまったく同じです: http://patrickmuff.ch/repo/

編集:私はObjective-Cに非常に慣れておらず、非常に経験が浅いため、ヒントやヘルプをいただければ幸いです。

4

1 に答える 1

1

現在、単位数 (時間、分、秒) のテキストを取得しています。これらの数値のバージョンを取得しfloatintそれらを使用して「ボックス」(インスタンスである必要がありUIViewます) のフレームを設定する必要があります。

あなたが示すスクリーンショットは、ビューフレームをすべて同じサイズに設定し、半透明の背景色で実際に行われます. 次に、各ビューには、単位値を使用してフレームの高さを設定するサブビューがあります。サブビューの背景色は完全に不透明になります。

もちろん、これはすべて、ビューを使用する代わりにコア グラフィックスを使用して行うことができます。


わかりました、あなたのコメントから、いいですね、背景は良いです。XIB で 3 つのビューを作成し、それらを背景領域の上に配置します。コードで使用できるように、アウトレットをそれらに接続します。背景色と高さをゼロに設定します。

コードでは、新しい単位値を取得するたびに、ビュー フレームを変更します (高さを増やし、「y」位置を減らすため)。

NSInteger hours = ...;

CGRect frame = self.hoursView.frame;

if ((NSInteger)frame.size.height != hours) { // check if we need to modify
    frame.origin.y -= (hours - frame.size.height);
    frame.size.height = hours;

    self.hoursView.frame = frame;
}
于 2013-08-04T10:38:27.697 に答える