码迷,mamicode.com
首页 > Web开发 > 详细

在UIWebView中媒体文件的展示和HTML字符串的展示

时间:2015-01-04 11:32:41      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:网页显示媒体文件   网页加载html文件   网页   web   uiwebview   

技术分享

UIWebView中媒体文件的展示和HTML字符串的展示


序言:

       UIWebView中不仅可以显示网页,还可以显示或者播放图片、视频、音频,甚至、PDF和Word文档。以上东西可以保存在Web上还可以压缩保存到本地。。。。



第一步:

我们今天来在Web上显示图片。

    NSString*path;
    path=[[NSBundle mainBundle]  pathForResource:@"one1" ofType:@"png"];
    NSData*data=[NSData dataWithContentsOfFile:path];
    [_ZSJwebView  loadData:data MIMEType:@"image/png" textEncodingName:nil baseURL:nil];
    

效果展示:

技术分享






第二步:  我们用Web来显示文档。


 
    NSString*path;
    path=[[NSBundle mainBundle]  pathForResource:@"df" ofType:@"doc"];
    
    NSURL*url=[NSURL  fileURLWithPath:path];
    
    NSURLRequest*request=[NSURLRequest   requestWithURL:url];
    [_ZSJwebView  loadRequest:request];
    
    

效果展示:

技术分享

完整代码:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UIWebViewDelegate>
{
    
    UIWebView*_ZSJwebView;
    
    
}

@end


#import "ViewController.h"
#import "Mylabel.h"

@implementation ViewController
-(void)viewDidLoad{
    
    
    _ZSJwebView=[[UIWebView alloc]initWithFrame:self.view.frame];
    [self.view addSubview:_ZSJwebView];
    
    
    
    
    
    
//    NSString*path;
//    path=[[NSBundle mainBundle]  pathForResource:@"one1" ofType:@"png"];
//    NSData*data=[NSData dataWithContentsOfFile:path];
//    [_ZSJwebView  loadData:data MIMEType:@"image/png" textEncodingName:nil baseURL:nil];
//    
    
    
    
    NSString*path;
    path=[[NSBundle mainBundle]  pathForResource:@"df" ofType:@"doc"];
    
    NSURL*url=[NSURL  fileURLWithPath:path];
    
    NSURLRequest*request=[NSURLRequest   requestWithURL:url];
    [_ZSJwebView  loadRequest:request];
    
    
    
    
    
    
    
    
    
    
}





 @end




技术分享


UIWebView中HTML字符串的显示

正文:

UIWebView不近可以用URL来导入界面,也可以用HTML来导入界面。


代码:

  
    [super viewDidAppear:animated];
    
    
    NSString*html=@"<b>[小明同学]</b><br />"@"<b>20154678<hr />"@"<b>[逐月]</b><br />" "http://blog.csdn.net/zhoushuangjian511/";
    [_ZSJwebView loadHTMLString:html baseURL:nil];
    

效果展示:

技术分享


注释:

UIwebView的datadetectorTypes的属性设置成UIDataDetectorTypeAll.这样HTML中的电话和URL就会变成链接。



完整代码:


#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UIWebViewDelegate>
{
    
    UIWebView*_ZSJwebView;
    
    
}

@end

#import "ViewController.h"
#import "Mylabel.h"

@implementation ViewController
-(void)viewDidLoad{
    
    
    _ZSJwebView=[[UIWebView alloc]initWithFrame:self.view.frame];
    _ZSJwebView.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
    _ZSJwebView.dataDetectorTypes=UIDataDetectorTypeAll;
    [self.view addSubview:_ZSJwebView];
    
    
    



}
-(void)viewDidAppear:(BOOL)animated{
    
    
    [super viewDidAppear:animated];
    
    
    NSString*html=@"<b>[小明同学]</b><br />"@"<b>20154678<hr />"@"<b>[逐月]</b><br />" "http://blog.csdn.net/zhoushuangjian511/";
    [_ZSJwebView loadHTMLString:html baseURL:nil];
    
    
    
}

 @end








友情快递:

技术分享

UITextView中的字符串里含有URL或者电话时,将自动显示链接


正文:

该功能默认情况下是关闭的。为OFF;将UItextView的后,就开启该功能。下面是该属性的其他几个:

dataDetectorTypeALL的属性
UIDataDetectorTypes 效果
UIDataDetectorTypePhoneNumber 只创建电话号码的链接
UIDataDetectorTypeLink 只创建URL的链接
UIDataDetectorTypeNone 不创建链接(默认)
UIDataDetectorTypeAll 及创建URL也创建电话链接




在UIWebView中媒体文件的展示和HTML字符串的展示

标签:网页显示媒体文件   网页加载html文件   网页   web   uiwebview   

原文地址:http://blog.csdn.net/zhoushuangjian511/article/details/42386781

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!