UIWebView載入Loading 兩種方法

2021-06-04 20:35:11 字數 1662 閱讀 3701

from: 

第一種方法:使用uiview and uiactivityindicatorview

//建立uiwebview 

webview = [ [ uiwebview alloc ] initwithframe : cgrectmake( 0 , 44 , 320 , 400 ) ] ;

[ webview setuserinteractionenabled: no ] ;

[ webview setbackgroundcolor : [ uicolor clearcolor ] ] ;

[ webview setdelegate : self ] ;

[ webview setopaque : no ] ;//使網頁透明

nsstring * path = @"" ;

nsurl * url = [ nsurl urlwithstring : path ] ;

[ webview loadrequest: [ nsurlrequest requestwithurl : url ] ] ;

//建立uiactivityindicatorview背底半透明view 

uiview * view = [ [ uiview alloc ] initwithframe : cgrectmake( 0 , 0 , 320 , 480 ) ] ;

[ view settag : 103 ] ;

[ view setbackgroundcolor : [ uicolor blackcolor ] ] ;

[ view setalpha : 0.8 ] ;

[ self .view addsubview : view ] ;

activityindicator = [ [ uiactivityindicatorview alloc ] initwithframe : cgrectmake( 0 .0f, 0 .0f, 32 .0f, 32 .0f) ] ;

[ activityindicator setcenter: view .center ] ;

[ activityindicator setactivityindicatorviewstyle: uiactivityindicatorviewstylewhite] ;

[ view addsubview : activityindicator] ;

[ self .view addsubview : webview] ;

[ view release ] ;

[ webview release ] ;

//開始載入資料

- ( void ) webviewdidstartload: ( uiwebview * ) webview  

//資料載入完

- ( void ) webviewdidfinishload: ( uiwebview * ) webview  

第二種方法:使用uialertview and uiactivityindicatorview

//載入網頁動畫

- ( void ) webviewdidstartload: ( uiwebview * ) webview 

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

UIWebView載入Loading 兩種方法

uiwebview載入loading.兩種方法 第一種方法 使用uiview and uiactivityindicatorview 建立uiwebview webview uiwebview alloc initwithframe cgrectmake 0,44,320,400 webview s...

UIWebView載入Loading 兩種方法

第一種方法 使用uiview and uiactivityindicatorview 建立uiwebview webview uiwebview alloc initwithframe cgrectmake 0,44,320,400 webview setuserinteractionenabled...

通過UIWebView載入讀取本地檔案

uiwebview是蘋果自帶的框架,也算是蘋果程式內部的瀏覽器,可以瀏覽web網頁,也可以開啟html htm pdf docx txt等格式的文字檔案,其實蘋果自帶的瀏覽器safari就是用uiwebview來實現的,具體原理簡單的說就是伺服器將mime的識別符號等放入傳送的資料中,然後告訴瀏覽器...