UIWebView

UIWebView是iOS sdk中一个最常用的控件。是内置的浏览器控件,我们可以用它来浏览网页、打开文档等等 
 
用UIWebView在当前程序中打开网页
  • NSString *query = [NSString stringWithFormat:@"http://www.baidu.com?q=苹果"];   
  • NSString *strUrl = [query stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];   
  • NSURL *url = [NSURL URLWithString:strUrl];     
  • NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];      
  • [webView loadRequest:requestObj];  

 

从APP 包内读取加载一个 HTML 文件

NSString *htmlPath = [[[NSBundle mainBundle] bundlePath]stringByAppendingPathComponent:@"webapp/loader.html"];


NSString *htmlString = [NSString stringWithContentsOfFile: htmlPathencoding:NSUTF8StringEncoding error:NULL];

[self.MyWebview loadHTMLString:htmlString baseURL:[NSURLfileURLWithPath:htmlPath]];

 

让UIWebView背景透明的方法,如下。

web_about.backgroundColor = [UIColor clearColor];
web_about.opaque = NO;

关键是在HTML里:
<body style="background-color: transparent">
text-indent:2em//设置所有段落的首行缩进2格

 

UIWebView加载Loading效果

  • UIView *view = [[UIView alloc] initWithFrame:CGRectMake(00320480)];   
  • [view setTag:103];   
  • [view setBackgroundColor:[UIColor blackColor]];   
  • [view setAlpha:0.8];   
  • [self.view addSubview:view];   
  •        
  • UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];   
  • [activityIndicator setCenter:view.center];   
  • [activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];   
  • [view addSubview:activityIndicator];   
  •        
  • [view release];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值