In the daily development, we will use a lot of webview for efficiency, for example, when we do a detail page, we return to you may be an HTML string, we need to display the current string to WebView above, so we need to have a certain understanding of HTML tags, Here we will use HTML tags and js to write a play hamster game, where we mainly explain the writing of HTML tags, as long as how and WebView adaptation involves the response to the layout of our next tutorial:
1. First, we'll create a new HTML file
2 full HTML tag and set encoding format for UTF-8
3 Add 10 mouse pictures in body, and add click event, when click Mouse to trigger JS function onclick= "Addscore (this);", Code as follows:
4 Put all the mouse pictures into the array, then turn on the timer, call the method twice per second, and randomly display eight mouse pictures
Show Mouse
function Showmouse () {
//Hide All Mouse
hideall ();
Control the number of clicks
times++;
Over 20 This end click
if (times>20) {
window.clearinterval (timer);
Alert ("Game Over, score" +score+ "points");
return;
}
Get all the mouse
var imgs=document.getelementsbytagname ("img");
Randomly displaying eight mice for
(var i=0;i<8;i++) {
var tem=math.random () *10;
tem= Math.Round (TEM);
var Node=imgs[tem]
node.style.display= "";
}
}
Hide All mouse
function Hideall () {
var imgs=document.getelementsbytagname ("img");
for (var i=0; i
5 Each Click we need to hide the current picture, and increase the score, every time the mouse added a point
Add fractional
function Addscore (cell) {
cell.style.display= "none";
score++;
document.getElementById ("label"). Innerhtml=score+ "Score";
6 HTML loaded into WebView display
UIWebView * Web=[[uiwebview alloc] Initwithframe:cgrectmake (0, 0, 375, 667)];
NSString * Path=[[nsbundle Mainbundle] pathforresource:@ "mouse.html" oftype:nil];
NSData * Data=[nsdata Datawithcontentsoffile:path];
NSString * str=[[nsstring alloc] initwithdata:data encoding:nsutf8stringencoding];
Web.scalespagetofit=yes;
[Web Loadhtmlstring:str Baseurl:nil];
[Self.view Addsubview:web];
The above is a small set of iOS for you to introduce the WebView loading HTML knowledge, hope to help.