1

私のブラウザー アプリケーションでは、応答が pdf ファイルの場合、NSURL 接続を使用してファイルをダウンロードしています。データを受信したら、UIprogressView を表示してダウンロード ステータスを表示します。ダウンロードが完了するまで、背景ビューの色を無効にして変更したい。

didReceiveResponse デリゲートでメソッドを呼び出して、progressView を作成し、backgroundcolor を変更して、parentView を無効にします。

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
[self.fileData setLength:0];
self.totalFileSize = response.expectedContentLength;
[self performSelectorOnMainThread:@selector(startProgressView) withObject:nil waitUntilDone:NO];
}

-(void) startProgressView
{
CGSize frameSize = self.view.frame.size;
CGFloat margin = 30.0;
CGPoint center = self.view.center;

 topLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, margin, frameSize.width-2*margin, 20.)];
 bottomLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, margin, frameSize.width-2*margin, 20.)];

[topLabel setText:@"downloading file"];
[topLabel setCenter:CGPointMake(center.x, center.y - 20.)];
[topLabel setTextAlignment:NSTextAlignmentCenter];

[bottomLabel setText:@"downloadstatus"];
[bottomLabel setCenter:CGPointMake(center.x, center.y + 20.)];
[bottomLabel setTextAlignment:NSTextAlignmentCenter];

self.progressBar = [[UIProgressView alloc] initWithFrame:
                    CGRectMake(0, margin, frameSize.width-2*margin, 20.)];
[self.progressBar setProgress:0];
[self.progressBar setCenter:center];

[self.view addSubview:topLabel];
[self.view addSubview:(self.progressBar)];
[self.view addSubview:bottomLabel];

 /*
CGRect frame = CGRectMake(0.0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
UIView *v = [[UIView alloc] initWithFrame:frame];
[v setBackgroundColor:[[UIColor alloc] initWithRed:255.0
                                             green:0.0
                                              blue:0.0
                                             alpha:0.1]];
[self.view insertSubview:v atIndex:0];
[v release];
*/

[self.view setBackgroundColor: [UIColor colorWithRed:0.0 green:255.0 blue:128.0/255 alpha:0.5]];
[self.view setUserInteractionEnabled:NO];
}

背景色を設定して、色付きの新しいビューを挿入しようとしましたが、背景色は変わりません。私が見逃しているものがあれば、誰かが指摘できますか。

4

2 に答える 2

2

アドバイスありがとうございます。背景色が表示されない理由がわかりました。viewcontroller(self.view) のメイン ビューには、その上にさらに 3 つのサブビューが含まれており、サブビューのため、self.view の背景色の変更は表示されません。背景色を変更するには、別のビューを作成するだけです

CGRect frame = CGRectMake(0.0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
backgroundView = [[UIView alloc] initWithFrame:frame];
[backgroundView setBackgroundColor:[[UIColor alloc] initWithRed:204./255 green:213./255 blue:216./255 alpha:0.5]];
[self.view addSubview:backgroundView];

progressView を追加する前に self.view に追加します。

于 2012-11-16T00:33:06.950 に答える
1

プログレスビューの背景色はほとんど表示されません。これは、背景色が赤のプログレスビューの画像です。

プログレスビュー

ご覧のとおり、赤い色は画像のごく一部にしかありません。
変更方法については、プロパティを設定するだけで十分です。

yourView.backgroundColor=[UIColor redColor];
// make it the color that you wish

よく見たい場合は、別の種類のビューに変更するか、progressTintColorプロパティを変更してください。

編集

ビューに背景で上書きしたいものがない場合は、自由にサブクラス化して内部に描画できます。ドキュメントを見ましたが、MacOSXのようにUIBezierPathインスタンスも必要ないようです。

- (void) drawRect:(CGRect)rect
{
    [[UIColor redColor] set];  
    UIRectFill(rect);
}
于 2012-11-15T20:47:20.520 に答える