@interface WebView : NSObject<UIWebViewDelegate> { UIWebView *webView; } -(void)closeAd:(id)sender; @end UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; //if Unity use UIView *view = UnityGetGLViewController().view; webView = [[UIWebView alloc] initWithFrame:view.frame]; webView.delegate = self; webView.hidden = YES; webView.scalesPageToFit = YES; UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button addTarget:self action:@selector(closeAd:) forControlEvents:UIControlEventTouchUpInside]; CGPoint topLeft = webView.frame.origin; button.frame = CGRectMake(topLeft.x, topLeft.y, 32, 32); [button setTitle:@"[X]" forState:UIControlStateNormal]; // Create URL request for image file location NSString *imageName = [[NSBundle mainBundle] pathForResource:@"404_Image" ofType:@"png"]; NSURL *imageURL = [NSURL fileURLWithPath: imageName]; NSURLRequest *imageRequest = [NSURLRequest requestWithURL: imageURL]; // Load image in UIWebView webView.scalesPageToFit = YES; [webView loadRequest: imageRequest]; // TODO animate webview when presenting [webView addSubview:button]; [view addSubview:webView]; -(void)closeAd:(id)sender { webView.hidden = YES; } //use delegates to handle on page load success and failure - (void)webView:(UIWebView *)webview didFailLoadWithError:(NSError *)error { //Show Image/Strings/HTML } - (void)webViewDidFinishLoad:(UIWebView *)webView { //do stuff }
Loading images in UIWebview - Page not found example iOS/Unity Example
Subscribe to:
Posts (Atom)