重複の可能性:
UILabel の点滅効果
UILabel
iPhoneでまばたきをする方法。私はグーグルとSOでも試しました。しかし、これらの質問は、ラベルをアニメーション化して色を変更することです。しかし、私は色を変える必要はありません。UILabel を点滅させる必要があります。出来ますか?
重複の可能性:
UILabel の点滅効果
UILabel
iPhoneでまばたきをする方法。私はグーグルとSOでも試しました。しかし、これらの質問は、ラベルをアニメーション化して色を変更することです。しかし、私は色を変える必要はありません。UILabel を点滅させる必要があります。出来ますか?
コードスニペットは次のとおりです。
コントローラでNSTimerプロパティを作成します。
@property (strong, nonatomic) NSTimer *timer;
viewDidLoadメソッドで、タイマーを開始します。
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(toggleLabelAlpha) userInfo:nil repeats:YES];
最後に、ラベルを切り替える関数を記述します
- (void)toggleLabelAlpha {
[self.label setHidden:(!self.label.hidden)];
}
楽しむ
1:クラスにNSTimerオブジェクトを作成します
NSTimer *updateTimer
2:タイマーをインスタンス化します-
updateTimer = [NSTimer scheduledTimerWithTimeInterval:1000
target:self
selector:@selector(appUpdate:)
userInfo:nil
repeats:YES];
3:タイマーが使用するセレクター(メソッド)を記述します-
- (void)appUpdate:(NSTimer*)theTimer
{
//Toggle the Text between a empty string and the text you want to display here
}