when we want to open the pdf file from a URL string then we use the UIWebView. In webview we can directly open the file by loading the url request.use the following function--
-(void)addWebViewOverLay:(UIWebView *)webView {
webView = [[UIWebView alloc] initWithFrame:CGRectMake(x, y, width , height)];
UIActivityIndicatorView *actInd=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
//Change the color of the indicator, this override the color set by UIActivityIndicatorViewStyleWhiteLarge
actInd.color=[UIColor blackColor];
//Put the indicator on the center of the webview
[actInd setCenter:webView.center];
//Assign it to the property
activityIndicator=actInd;
[activityIndicator setHidesWhenStopped:YES];
//Add the indicator to the webView to make it visible
[webView addSubview:activityIndicator];
webView.delegate=self;
[webView setBackgroundColor:[UIColor grayColor]];
NSURL *targetURL = [NSURL URLWithString:@"Enter URL Here"];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[activityIndicator startAnimating];
[webView setScalesPageToFit:YES];
[[webView layer] setCornerRadius:10];
[webView setClipsToBounds:YES];
// Create colored border using CALayer property
[[webView layer] setBorderColor:
[[UIColor colorWithRed: 43/255.0 green:124/255.0 blue:24/255.0 alpha:1.0] CGColor]];
[[webView layer] setBorderWidth:2.75];
UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
closeButton.tag=2222;
[closeButton setFrame:CGRectMake(webView.frame.size.width-5, 5, 26, 26)];
[closeButton setImage:[UIImage imageNamed:@"icon_close.png"] forState:UIControlStateNormal];
[closeButton addTarget:self action:@selector(closeWebView:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:webView];
[[self view] addSubview:closeButton];
}
here we use delegate of uiwebview to stop the activity indicator.
-(void)webViewDidFinishLoad:(UIWebView *)webView {
[activityIndicator stopAnimating];
}
0 Comment(s)