Make a simple browser that contains the URL entry box, the Search button, the Forward, rewind button, UIWebView on these simple controls.
Uitextfield: Used to enter the URL;
Uibuttom: Realize forward, backward, search and other functions;
UIWebView: Implement Web page display.
Preparatory work:
Right-Info.plist and Open as Source code and add the following code snippet after opening:
1 <key>NSAppTransportSecurity</key>2 <dict>3 <key> Nsallowsarbitraryloads</key>4 <true/>5 </dict>
The above code snippet function: Some URLs for HTTP, to make HTTPS, the specific principles explored after the additional.
To this, the specific code that implements the browser function is as follows:
1 #import "ViewController.h"2 3 @interfaceViewcontroller () {4 5 //define global variables, individual controls6UIWebView *Mywebview;7UIButton *Backbutton;8UIButton *Goforbutton;9Uitextfield *Urlfield;TenUIButton *SearchButton; One } A - @end - the @implementationViewcontroller - -- (void) Viewdidload { - [Super Viewdidload]; + - //Add a browser view, +Mywebview = [[UIWebView alloc]initwithframe:cgrectmake (0, -, Self.view.frame.size.width, self.view.frame.size.height- -)]; A [Self.view Addsubview:mywebview]; at - - //URL Input Box -Urlfield = [[Uitextfield alloc]initwithframe:cgrectmake (0, -, self.view.frame.size.width- -, -)]; -Urlfield.borderstyle =Uitextborderstyleroundedrect; -urlfield.text=mywebview.request.URL.absoluteString; in [Self.view Addsubview:urlfield]; - to + - //Search Button theSearchButton = [[UIButton alloc]initwithframe:cgrectmake (self.view.frame.size.width- -, -, -, -)]; *Searchbutton.backgroundcolor =[Uicolor Redcolor]; $[SearchButton Settitle:@"Search"Forstate:uicontrolstatenormal];Panax Notoginseng [SearchButton addtarget:self action: @selector (search:) forcontrolevents:uicontroleventtouchupinside]; - [Self.view Addsubview:searchbutton]; the + A //return button theBackbutton = [[UIButton alloc]initwithframe:cgrectmake (0, self.view.frame.size.height- -, -, -)]; +Backbutton.backgroundcolor =[Uicolor Redcolor]; -[Backbutton Settitle:@"return"Forstate:uicontrolstatenormal]; $ [Backbutton addtarget:self Action: @selector (backfbution:) forcontrolevents:uicontroleventtouchupinside]; $ [Self.view Addsubview:backbutton]; - - //Forward Button theGoforbutton = [[UIButton alloc]initwithframe:cgrectmake (self.view.frame.size.width- -, self.view.frame.size.height- -, -, -)]; -Goforbutton.backgroundcolor =[Uicolor Redcolor];Wuyi[Goforbutton Settitle:@"forward"Forstate:uicontrolstatenormal]; the [Goforbutton addtarget:self Action: @selector (gofobution:) forcontrolevents:uicontroleventtouchupinside]; - [Self.view Addsubview:goforbutton]; Wu - About } $ - - //returns the button binding event --(void) Backfbution: (ID) sender{ A [Mywebview GoBack]; + } the - $ //Forward button bind event the-(void) Gofobution: (ID) sender{ the [Mywebview GoForward]; the } the - in //Search Button Binding events the-(void) Search: (ID) sender{ the [Mywebview loadrequest:[nsurlrequest Requestwithurl:[nsurl URLWithString:urlField.text]]; About } the the the- (void) didreceivememorywarning { + [Super didreceivememorywarning]; - } the Bayi @end
The effect is as follows (please disregard the colors used in the UI ...). ):
There is a problem, that is, I can click on a URL in Baidu after a link to open the URL, but open the browser URL in the box after the URL is still the previous one, did not change to the current site address. The problem is left behind ...
iOS Development-ui Learning-uiwebview, Simple browser making