NSCoriolisBlog » Blog Archive » Add an UIProgressView or UIActivityIndicatorView to your UIAlertView
サンプル
こんな感じ。
"START"ボタンを押すと UIAlertView がポップアップし、プログレスバーが進んでいく。
プログレスバーが 100% になると UIAlertView を閉じる。
実装
UIAlertView のサブビューとして UIProgressView を追加する。追加位置はプログラム内で決め打ちしている。
- (IBAction)start:(id)sender
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Information"
message: @"Please wait..."
delegate: self
cancelButtonTitle: nil
otherButtonTitles: nil];
UIProgressView* progressView = [[UIProgressView alloc]
initWithFrame:CGRectMake(30.0f, 80.0f, 225.0f, 90.0f)];
[alertView addSubview:progressView];
[progressView setProgressViewStyle: UIProgressViewStyleBar];
[progressView release];
[alertView show];
[alertView release];
progressValue = 0.0f;
NSDictionary* userInfo =
[NSDictionary dictionaryWithObjectsAndKeys:
progressView , kProgressViewKey,
alertView , kAlertViewKey,
nil];
[NSTimer scheduledTimerWithTimeInterval:0.1f
target:self
selector:@selector(updateInformation:)
userInfo:userInfo
repeats:YES];
}
サンプルでは NSTimer を使って 0.1秒毎にプログレスバーを 1% 進めている。なおキャンセルボタンを表示するとこんな感じ。
もともと余白が無いところなので仕方が無い。ボタンを出す場合はメッセージの表示をやめてその位置にプログレスバーを表示するしかない。
ソースコード
ProgressBarOnAlertView at 2010-12-18 from xcatsan/iOS-Sample-Code - GitHub





335g says:
2010年12月23日 23:27
delegate method の
- (void)willPresentAlertView:(UIAlertView *)alertView
でAlertViewのサイズを出現前に変更できたと思いますよ。
ボタンの位置もsubviewsから設定すればいじれます。
335g says:
2010年12月23日 23:27
delegate method の
- (void)willPresentAlertView:(UIAlertView *)alertView
でAlertViewのサイズを出現前に変更できたと思いますよ。
ボタンの位置もsubviewsから設定すればいじれます。
xcatsan says:
2010年12月26日 15:00
教えてもらった方法で AlertViewサイズ変更とボタンの位置変更ができました。情報ありがとうございました!
xcatsan says:
2010年12月26日 15:00
教えてもらった方法で AlertViewサイズ変更とボタンの位置変更ができました。情報ありがとうございました!
335g says:
2010年12月27日 21:35
いえいえ。
こちらこそいつも参考にさせてもらってます。ありがとうございます。
自分にわかる事であればまたコメントさせていただきます。
335g says:
2010年12月27日 21:35
いえいえ。
こちらこそいつも参考にさせてもらってます。ありがとうございます。
自分にわかる事であればまたコメントさせていただきます。