Welcome to the club of searching for an overly simple UIWebView a.k.a. WebKit example! In this example, I’ll show you simply how to hand code a quick UIWebView into your program as well as to add a UIActivityIndicatorView a.k.a. an activity indicator. Without jabbing Apple too hard here, the documentation is pretty bad and that is why it’s nice to have an example just shown to you as-is. I hope this example helps shine a light on the situation for anyone wanting to implement a nice and quick Apple iPhone WebKit solution.
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController <UIWebViewDelegate>
{
UIWebView *myWebView;
UIActivityIndicatorView *activityIndicator;
}
/*
Inside the @implementation FirstViewController ...
*/
- (void)viewDidLoad { //We have a NIB file in play here, so I dropped the loadView here. Just make sure that your loadView is not getting called twice!
[super viewDidLoad];
[self loadView];
}
- (void)loadView {
UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
self.view = contentView;
CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
webFrame.origin.y = 0.0f;
myWebView = [[UIWebView alloc] initWithFrame:webFrame];
myWebView.backgroundColor = [UIColor blueColor];
myWebView.scalesPageToFit = YES;
myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
myWebView.delegate = self;
[self.view addSubview: myWebView];
[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.maxpowersoft.com/"]]];
activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
activityIndicator.center = self.view.center;
[self.view addSubview: activityIndicator];
}
- (void)dealloc {
[activityIndicator release];
[myWebView release];
[super dealloc];
}
#pragma mark WEBVIEW Methods
- (void)webViewDidStartLoad:(UIWebView *)webView
{
// starting the load, show the activity indicator in the status bar
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[activityIndicator startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
// finished loading, hide the activity indicator in the status bar
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[activityIndicator stopAnimating];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
// load error, hide the activity indicator in the status bar
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
// report the error inside the webview
NSString* errorString = [NSString stringWithFormat:
@"<html><center><br /><br /><font size=+5 color='red'>Error<br /><br />Your request %@</font></center></html>",
error.localizedDescription];
[myWebView loadHTMLString:errorString baseURL:nil];
}
That is all there is to it. It’s really simple as you can see. Feel free to copy and paste accordingly.
分享到:
相关推荐
自定义UIActivityIndicatorView,包括颜色、图案、转动速度等等。 注意:请在Mac下解压使用
#iOS-Custom-Activity-Indicator如何使用?微调器的实现TJSpiner 具有实现或改变颜色、大小图案、图像、旋转速度等的能力。 1. 线基微调器的实现(类似于 iOS 活动指示器)。 A. 您可以更改微调器的内外半径 B. 您...
该源码由源码天堂IOS动画(Animation)频道免费提供下载。动画Activity Indicator View实现各种各样的图形、动画效果。例如图形变换、平移、渐变、缩放、旋转等功能。
适用于 iOS 的 NetworkActivityIndicator Version 0.1.1 Apache Cordova 插件。 1. 说明 这个插件允许你在 iOS 上显示和隐藏状态栏的网络活动指示器。 您甚至可以同时启动多个 NetworkActivityIndicator ...
iOS 自定义 IBDesignable Activity Indicator 注意: DUIActivityIndicator 与Swift 1.2兼容。 作者 丹尼尔·(dan- ), 执照 DUIActivityIndicator在 MIT 许可下可用。 有关详细信息,请参阅许可证文件。
来源:Licence:BSD平台:iOS设备:iPhone / iPad作者:Hezi Cohen 自定义UIActivityIndicatorView,包括颜色、图案、转动速度等等。 Code4App编译测试,适用环境:Xcode 4.3, iOS 5.0。
内容索引:脚本资源,jQuery,jQuery插件,透明层 jQuery透明层插件 NETEYE Activity Indicator及示例,它可以呈现一个半透明效果的指示器,可以用于SVG 或 VML.它可以在任何浏览器上运行,要求JQuery 1.4.2(或更高).除此...
Dinapoli indicator target. For trading forex. Best indicator
给ViewPager添加indicator
Flutter自定义TabBar的Indicator 实现秒杀Tab效果
语言:English 以来,自上次提交到GitHub存储库的链接旁边的天数。... 您是否曾在github上列出只能在您遵循追随存储库链接后找到“令人敬畏的... 它也是开源(在github上看到derhackler / githubactivity indersicator)。
CircularProgressIndicator - 可定制的循环进度指示器
react-native-activity-indicator-ios 等待一秒钟的 ActivityIndicatorIOS 包装器。 这解决了什么问题? 本机 ActivityIndicatorIOS 立即显示微调器(假设您没有将设置为false ),因为。 这个包装器将在...
Android Tablayout 的Indicator 长度的修改(这里只适用于:1.指示器长度和文字长度相等,2.指示器长度填满整个TabItem)
indicator binary options clubinarias
pinbar indicator for forex trading and scalping
TabLayout我相信大家都有使用过,但是官方并没有对Indicator可以设置为图片的支持,只能是简单的水平线,也就是滑动杆那个玩意,那么如何做到可以用图片来做**指示器**呢?
this indicator to optimized analyse forex trading for all pair and any time frame
Grail-Indicator is one of Binary Option indicator System
Tick based RSI like custom indicator function written by C++.