Placed in: Home arrow Programming arrow Webdesign arrow Build native-looking apps for iOS
Build native-looking apps for iOS

Lately, I've been messing around with cool HTML5 stuff a lot. One of the things that HTML5 is trying to reach, is the market of mobile devices. A long time ago (when I got my first iPhone), I wrote an article on how to add a webclip for easy access to your website. But since then, I've learned a couple of more things on how to build native-looking apps for iOS using only HTML.

iOS HTML Template

I've created a template/boilerplate that you can use for your next project to create native looking apps for iOS (more specifically: Mobile Safari) using nothing but HTML. Simply build your website starting with this template, bookmark it and you're done.

View or download the source code and read the comments carefully to see what's needed to create a native looking app using only HTML.

Demo iOS HTML Template   Download iOS HTML Template

If you don't feel like fully digging into the source, but learn the pieces bit by bit, feel free to read on further. Take note that this will only work when the user bookmarks your webpage. The changes to any existing projects can be made easily, just make the following changes in the head section of your page and you're ready to go!

Set the viewport

First, we'll need to provide the browser more information about how the webpage should be displayed. This will ensure the application is rendered properly and not scaled when rotating/zooming. To do this, we need to set the viewport property to a 1.0 scale and prevent the user from scaling anymore.

 
<meta name="viewport" content="width=device-width;
    initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>

You'll have to keep in mind that your user can now not scale anything on your site anymore. Make your font/links/buttons etc. big enough for him to actually read or press.

Make it fullscreen

Sadly, you can't make a HTML application go truly fullscreen (something which a native application can do). You can almost achieve this effect by hiding the browser URL bar (top) and the navigation bar (bottom). Both so-called Safari-bars can be hidden using the following code:

 
<meta name="apple-mobile-web-app-capable" content="yes" />

Pretty cool! When you now bookmark the page, it'll (almost) not look like as if you're visiting a website, but using a real app. But there's more we can do!

Change the status bar style

With HTML, you even get the power to change the status bar style of the iOS device. The status bar is the bar totally on top of the device, which is always visible and contains information about your carrier, battery life etc. We can change this by adding the following line:

 
<meta name="apple-mobile-web-app-status-bar-style"
    content="black-translucent" />

Valid values for content are: default (white), black and black-translucent. If set to default or black, the content is displayed below the status bar. If set to black-translucent, the content is displayed under the bar.

Add a Home icon

The Home icon (also known as webclip, Springboard icon or Apple Touch Icon) can also be controlled using HTML. This is the kind of icon will see on their home screen in order to start the application. It's pretty easy to create one yourself, but there are a couple of things you have to keep in mind.

By default, Mobile Safari searches for a file named apple-touch-icon.png in the root directory of your website. If it can't find any image there, you can specify it using the code below. Make sure the image has a dimension of 114x114 and is a PNG file. The glossy finish and resizing for the different devices will be done automatically.

Apple Touch Icon
 
<link rel="apple-touch-icon"
    href="images/apple-touch-icon.png" />

Using my template, the result will look like this:

Apple Touch Icon

If you don't want the glossy finish, use apple-touch-icon-precomposed instead of apple-touch-icon. The result will look like this:

Apple Touch Icon Precomposed

That looks great for making your app look even more like a native app. But, we can do even more stuff.

Add a startup image

You can even add a startup image (also known as a splash screen) to your HTML application, to show to the user while the application loads. This is the one that I'm using in my template:

Startup image

Take note this file exactly needs to be 320x460 for iPhone/iPod or 1004x768 for iPad, and is a PNG file. Also, this only works if apple-mobile-web-app-capable is set to yes.

Block rubber banding

Rubber banding (also known as elastic scroll) is the effect you see when you pull down/push up the page, see a grey area (which indicates the bottom of the page) and flicks back. In most native applications, this is something you don't see and that's why we want to prevent it. Take note, by using this code, the user can't scroll on your page anymore.

 
<head>
 
    <script>
    function BlockElasticScroll(event) {
        event.preventDefault();
    }
    </script>
 
</head>
<body ontouchmove="BlockElasticScroll(event);">
 
</body>

Sadly, this solution isn't fully waterproof (sometimes, it doesn't work). For a more solid solution, check out ScrollFix.

Javascript

In JavaScript, you can use window.navigator.standalone boolean to detect wether the page is being viewed on your website, or as a standalone application. Use the following booleans to check which device the user is using:

 
var isIPhone = navigator.userAgent.indexOf("iPhone") != -1 ;
var isIPod = navigator.userAgent.indexOf("iPod") != -1 ;
var isIPad = navigator.userAgent.indexOf("iPad") != -1 ;
var isIOs = isIPhone || isIPod || isIPad ;

Conclusion

This template can really help you make your HTML app give a more native app iOS look and feel. It's great that the same code works for the iPhone/iPod (only the iPad has some sizing issues with the startup image). You can use JavaScript to give feedback to the user that they should bookmark your application once they visit your website to get the whole experience!

Later on, you could add a manifest file to take your application offline to use your application even when you don't have an active internet connection! I might cover that in another tutorial later.

Demo iOS HTML Template   Download iOS HTML Template

Did I miss anything? Do you have more tips you want to share? Feel free to do!


Tags:  ios iphone ipad native html

Interested in this topic? You might enjoy another article I've written called

Did you like this article? Subscribe to my feed or email to keep updated on new articles.

Spread the word and submit to:
Digg!Reddit!Del.icio.us!Facebook!StumbleUpon!
Comments
Add NewSearchRSS
lookaze - Very well done!   2011-12-13 09:28:44
Gravatar image Very helpful, excellent tutorial, good explanations! Keep it coming Marco!
Mikael Kindborg - Clear and informative tutorial!   2011-12-13 15:49:38
Gravatar image Thanks for this great tutorial! I am working on HTML5 support for the MoSync cross-platform mobile development tool, and many of the techniques you cover are or course very useful also when making a web app packaged as a native app. Here is an introduction to MoSync HTML5 development in case you are curious: http://www.mosync.com/documentation/manualpages/how-create-html5-project-mosync
JCH - developer   2011-12-13 18:46:26
Gravatar image AWESOME tutorial Marco! Thank you.

For the demo, the startup image does not display on my iPad2 with IOS 5.0.1

jch
Marco - True!   2011-12-14 09:24:16
Gravatar image Yup, that's true - it's because the template only includes a 320x460 file for iPhone/iPod support, but not a 1004x768 file for iPad support (see the article for the reference) ;) .
Aluminium Box - Amazing Tutorial again   2011-12-14 08:19:43
Gravatar image Hey Marco, thank you so much. Amazing, awsome and good to know. Greetings from Germany...
Astteco - Interesting   2011-12-15 11:36:17
Gravatar image Good tips, usefull. ;)
Teen Rings - Teen Rings   2011-12-21 13:07:52
Gravatar image It's really AWESOME tutorial Marco! Thank you for your great job!

Please keep it up!
snowing - cheap oakley sunglasses   2012-03-22 02:03:18
Gravatar image Popular Products and solutions: 0-9we are a top cheap oakley sunglasses, Here lays the invisible magic formula off man” s accomplishments eyeglasses manucturer, thanks for visiting make contact with for additional particulars. cartier real wood style oakley sunglasses for cheap in the market place, cartier frames glasses glasses or contact lenses, What perform a person imply if they say they like somebody? cartier glasses or contact lenses, more cost-effective cartier cheap oakley sunglasses sale wholesaler My personal thinking they will counter-top; my personal dialog they will distrust, endorsed cartier glasses or contact lenses available for sale, there's a “ The latter variety is the obsessiveone; buflo cartier eyeglasses, cartier discount oakley sunglasses sale on ebay, duplicate cartier manucturer For the reason that terms worth mentioning scrolls are eaten by simply my personal classy terraces store.
takeyourjerseys - take your jerseys   2012-05-25 07:51:15
Gravatar image New Jersey Devils were established in 1982. Their head coach is Jacques Lemaire and their captain is in vacant. The arena is Prudential Center in Newark. New Jersey Devils Jersey are owned by Jeffrey Vanderbeek, who bought them in 2004 for $125 mil and now they are worthy $218 mil. The colors of the New Jersey Devils Jersey are red, black and white. We provide the top quality NHL Jersey in lower price. Show your support to New Jersey Devils Jersey with this gorgeous jersey."
NHL New Jersey Devils #15 Jamie Langenbrunner CCM Red and Green n
takeyourjerseys - take your jerseys   2012-06-12 05:53:23
Gravatar image Kevin Durant Jersey--http://www.takeyourjerseys.com/oklahoma-city-thunder-jerseys/nba-kevin-durant-oklahoma-city-thunder-35-jersey-black-p-2582.html
Oklahoma City Thunder --http://www.takeyourjerseys.com/oklahoma-city-thunder-jerseys-c-93_114.html

uMMauRban - nice   2012-10-02 17:34:59
Gravatar image nice tutor! good job...:)
hey i just wanna ask you.. may i know a sample for whole a process.. i mean the final html and ready to put on our website? the arranged html... i need some example please..

Regards,
uMMauRban - nice..   2012-10-02 17:35:55
Gravatar image nice tutor! good job...:)
hey i just wanna ask you.. may i know a sample for whole a process.. i mean the final html and ready to put on our website? the arranged html... i need some example please..

Regards,
uMMauRban - help please...   2012-10-04 17:00:31
Gravatar image so, how we put it together on our templates? i use blogspot.. maybe u can give me the final result? very useful article here.. thanks b4:)
keya Directory - thanks for Demo   2012-11-27 12:45:14
Gravatar image AWESOME tutorial Marco! Thank you.

For the demo, the startup image does not display on my iPad2 with IOS 5.0.1
Ankita   2012-12-27 11:26:37
Gravatar image :( i can not download demo or source code...please help
Jones - Update?   2013-01-29 21:55:58
Gravatar image Nice tutorial!

Wonder if there is going to be an update to this? Something with the new iPad and the iPhone 5 for example.

I noticed that the Block rubber banding doesn't work on the iPhone 5.
Read more...
Name:
Email:
  Gravatar enabled.
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
 
Security Image
Please input the anti-spam code that you can read in the image.
Unsubscribe from e-mail notifications.
 
Next >
Subscribe

Subscribe to Marcofolio