WebView loading Html_ios in IOS

Source: Internet
Author: User
Tags html tags

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.