ファイルのアップロード処理を表示するUIAlertViewにUIProgressViewを表示したい。しかし、私は検索しすぎて、そのリンクでも見つけましたが、それを行うことができません。私はこれからアイデアを得ることができません
一番簡単にできる方法を知っている人がいたら教えてください。
ファイルのアップロード処理を表示するUIAlertViewにUIProgressViewを表示したい。しかし、私は検索しすぎて、そのリンクでも見つけましたが、それを行うことができません。私はこれからアイデアを得ることができません
一番簡単にできる方法を知っている人がいたら教えてください。
これを行うのに問題があり、最終的には次のようになりました。
av = [[UIAlertView alloc] initWithTitle:@"Running" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
progressView.frame = CGRectMake(0, 0, 200, 15);
progressView.bounds = CGRectMake(0, 0, 200, 15);
progressView.backgroundColor = [UIColor blackColor];
[progressView setUserInteractionEnabled:NO];
[progressView setTrackTintColor:[UIColor blueColor]];
[progressView setProgressTintColor:[UIColor redColor]];
[av setValue:progressView forKey:@"accessoryView"];
[av show];
このコードを試してください...
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"" message:@"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
UIProgressView *pv = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
pv.frame = CGRectMake(20, 20, 200, 15);
pv.progress = 0.5;
[av addSubview:pv];
[av show];
これはあなたの質問に完全には答えませんが、この機能が組み込まれているサードパーティのコントロールであるMBProgressHudを試してください。Github で提供されている例を使用すると、すぐに慣れることができます。
このコードを試してください。アクティビティ インジケーターには YES を、progressView には NO を入力します
- (void) createProgressionAlertWithMessage:(NSString *)message withActivity:(BOOL)activity
{
progressAlert = [[UIAlertView alloc] initWithTitle: message
message: @"Please wait..."
delegate: self
cancelButtonTitle: nil
otherButtonTitles: nil];
// Create the progress bar and add it to the alert
if (activity) {
activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityView.frame = CGRectMake(139.0f-18.0f, 80.0f, 37.0f, 37.0f);
[progressAlert addSubview:activityView];
[activityView startAnimating];
} else {
progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(30.0f, 80.0f, 225.0f, 90.0f)];
[progressAlert addSubview:progressView];
[progressView setProgressViewStyle: UIProgressViewStyleBar];
}
[progressAlert show];
[progressAlert release];
}
alerviewdelegate メソッドを利用しない理由
- (void)willPresentAlertView:(UIAlertView *)alertView
これの利点は、iOS がこの時点でこれを事前に計算しているため、alertview が実際に画面に表示されるサイズを確認できることです。そのため、マジック ナンバーや、Apple が警告するクラスをオーバーライドする必要はありません。
そして、iOS7の時点で、フレームサイズをハードコーディングするのではなく、常にアプリから計算するか、それらの線に沿って何かを計算するように言っているAppleからのドキュメントを読んだことを覚えていますか?
- (void)willPresentAlertView:(UIAlertView *)alertView
{
CGRect alertRect = alertview.bounds;
UIProgressView *loadingBar = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
loadingBar.bounds = CGRectMake(0, 0, alertRect.width, HEIGHT_YOU_WANT);
// Do what ever you want here to set up the alertview, as you have all the details you need
// Note the status Bar will always be there, haven't found a way of hiding it yet
// Suggest adding an objective C reference to the original loading bar if you want to manipulate it further on don't forget to add #import <objc/runtime.h>
objc_setAssociatedObject(alertView, &myKey, loadingBar, OBJC_ASSOCIATION_RETAIN); // Send the progressbar over to the alertview
}
ローディング バーへの参照をプルするには
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
次に使用します
UIProgressView *loadingBar = objc_getAssociatedObject(alertView, &myKey);
定義したことを忘れないでください
#import <objc/runtime.h>
static char myKey;
クラス宣言の先頭に
これはアラート ビューの作成です
UIAlertController* alert=[UIAlertController alertControllerWithTitle:@"メッセージ" メッセージ:@"これはテストです" preferredStyle:UIAlertControllerStyleAlert];
テキストフィールドを追加する
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField)
{
textField.placeholder=@"Enter Text label";
[textField setBorderStyle:UITextBorderStyleRoundedRect];
textField.backgroundColor=[UIColor whiteColor];
}];
ビューに追加しました
[self presentViewController:alert animation:YES 完了:nil];