今ココ
「時刻表時が出来た所」
次は
「秒数に応じて色が変化する」を試そうー
■ やってみよう
「秒数に応じてラベルの色が変化する」を要素に分解すると
・条件分岐の構文
・ラベルの背景色
と思うので、これらを調べながらトライ
・簡単そうなラベルの背景色を付ける所から
XCodeラベルの色などUIColorで指定する方法 - Naak.comを参考
にして
-------------------------------
_myLabel01.backgroundColor = [UIColor colorWithRed:0.0 green:0.5 blue:0.5 alpha:0.3];
-------------------------------
他にも参考
UILabel - iPhoneアプリ開発の虎の巻
・条件分岐は
逆引きObjective-C for iPhoneアプリ - 条件分岐(if, switch)を参考にして
-------------------------------
switch (second) {
case 1:
_myLabel6.backgroundColor = [UIColor colorWithRed:0.0 green:0.5 blue:0.5 alpha:0.3];
break;
case 5:
_myLabel6.backgroundColor = [UIColor colorWithRed:0.0 green:1.0 blue:0.5 alpha:0.3];
break;
case 10:
_myLabel6.backgroundColor = [UIColor colorWithRed:1.0 green:0.2 blue:0.5 alpha:0.3];
break;
case 15:
_myLabel6.backgroundColor = [UIColor colorWithRed:1.0 green:0.5 blue:0.1 alpha:0.3];
break;
default:
_myLabel6.backgroundColor = [UIColor colorWithRed:1 green:1 blue:0.5 alpha:0.3];
break;
}
-------------------------------
switchの()内のsecondは
時刻表時に作った秒の変数にする事で、
時刻の秒に応じて条件が分岐
以上を使い
出来たのがこんな感じに
時刻の秒数が1,5,10,15,の時に色が変化し
残り時刻の秒数はswitch分のdefaultで指定
(秒数は一番下の41の所)
0 件のコメント:
コメントを投稿