在UIWebView中媒體檔案的展示和HTML字串的展示

來源:互聯網
上載者:User

標籤:網頁顯示媒體檔案   網頁載入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*[email protected]"<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*[email protected]"<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字串的展示

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.