2012-11-15 4 views
1

브라우저 응용 프로그램에서 응답이 PDF 파일이면 NSURL 연결을 사용하여 파일을 다운로드하고 있습니다. 데이터를 받으면 UIprogressView를 표시하여 다운로드 상태를 표시합니다. 다운로드가 완료 될 때까지 백그라운드보기의 색을 비활성화하고 변경하고 싶습니다. didReceiveResponse 위임에iOS에서보기의 배경색을 변경하십시오.

은 내가 배경 색상을 설정하고 변경되지 않는 색상이지만 배경색으로 새로운 뷰를 삽입 시도 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]; 
} 

을 progressView을 만들고있는 backgroundColor을 변경하고 해제하는 메서드를 호출합니다. 누락 된 것이 있으면 누군가가 지적 할 수 있습니까?

+0

색상 설정을 제외하고 다른 모든 기능이 작동합니까? (두 개의 레이블과 진행률 막대가 보입니까)? – rdelmar

+0

예 배경색을 제외한 다른 모든 것이 작동합니다. 나는 그 이유를 알아 냈다. viewcontroller (self.view)의 주요 뷰는 그 위에 3 개의 하위 뷰를 포함하며 self.view의 배경색을 변경하는 것은 하위 뷰로 인해 보이지 않습니다. – codemaster

답변

2

감사 모든 조언을 위해 : 나는 당신도 맥 OS X와 ​​같은 UIBezierPath 인스턴스를 필요로하지 않는 것 같다, 설명서를 보았다. 배경색이 보이지 않는 이유를 알아 냈습니다. 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에 추가 배경색을 변경합니다.

1

진행 뷰의 배경색은 거의 visible.This 빨간색 배경 색상으로 진행 뷰의 이미지입니다 :

progress view

당신은 붉은 색의 작은 부분 만입니다 볼처럼 이미지. 를 변경하는 방법에 관해서는
, 그것을 설정하는 것이 충분하면 재산입니다 :

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

당신이 잘 볼보기의 또 다른 종류로 변경, 또는 progressTintColor 속성을 변경하려면

. 뷰가없는 당신이 배경에 오버라이드 (override) 할 무언가가있는 경우

편집

, 당신은 자유롭게 서브 클래스와 그 안에 그릴 수 있습니다.

- (void) drawRect:(CGRect)rect 
{ 
    [[UIColor redColor] set]; 
    UIRectFill(rect); 
} 
+0

진행률 표시 줄이 추가 된보기의 배경색을 변경하려고합니다. 진행률 막대를 self.view에 추가했습니다. self.view의 배경색을 변경하는 것이 진행률보기에만 필요한 이유는 무엇입니까? – codemaster

+0

진행보기는 UIView의 하위 클래스이므로 이러한 속성을 추가합니다. 어떤보기가 진행률 표시 줄에 추가되지는 않지만 배경에 아무 것도없는 경우 UIBezier 경로를 사용하여 그 안에 그릴 수 있습니다. 곧 제공 될 예정입니다. –

관련 문제