UIWebView的基本用法

2021-07-09 17:35:48 字數 1287 閱讀 3829

uiwebview是繼承自uiview的 是獲取瀏覽器的控制項 下面讓我們來了解它的用法:

// 第一步 宣告屬性

@property (nonatomic, strong) uiwebview *webview;

初始化self.webview = [[uiwebview alloc] initwithframe:[uiscreen mainscreen].bounds]

nsurlrequest *request = [[nsurlrequest alloc] initwithurl:[nsurl urlwithstring:self.model.commentsurl]];

[self.webview loadrequest:request];

self.webview.autoresizingmask = uiviewautoresizingflexiblewidth;

self.webview.autoresizingmask = uiviewautoresizingflexibleheight;

// 自適應螢幕的寬度

//    self.webview.scalespagetofit = yes;

加到self.view上面

[self.view addsubview:self.webview];

他也有自己的**方法 首先引入** 

self.webview.delegate = self;

下面是他的**方法:

開始載入

- (void)webviewdidstartload:(uiwebview *)webview;

載入結束

- (void)webviewdidfinishload:(uiwebview *)webview ;

載入出現錯誤

- (void)webview:(uiwebview *)webview didfailloadwitherror:(nullable nserror *)error ;

下面是我們在載入時候的一些處理 為了更好的使用者體驗

- (void)webviewdidstartload:(uiwebview *)webview

在結束載入和載入出現錯誤的時候根據tag值取到view 並移除

// 載入結束

- (void)webviewdidfinishload:(uiwebview *)webview

// 載入出現錯誤

- (void)webview:(uiwebview *)webview didfailloadwitherror:(nullable nserror *)error

獲取UIWebView的高度

昨天做專案的時候 忘記了如何獲取web的高度趕緊記錄下,希望對你也有幫助。獲取web高的的方法有很多,今天只寫了最近用到的一種,獲取html的demo高度。下面還是不多說直接上 import viewcontroller.h inte ce viewcontroller end implementa...

mysql 的基本用法 mysql基本用法

mysql 5.1 中文參考手冊 show databases 顯示資料庫 drop database 資料庫名 刪除資料庫 set names utf8 設定資料庫編碼為utf 8 source x 資料庫名.sql 匯入乙個資料庫 use 資料庫名 嘗試訪問資料庫 create database...

mysql 的基本用法 mysql基本用法

mysql 5.1 中文參考手冊 show databases 顯示資料庫 drop database 資料庫名 刪除資料庫 set names utf8 設定資料庫編碼為utf 8 source x 資料庫名.sql 匯入乙個資料庫 use 資料庫名 嘗試訪問資料庫 create database...