The iPhone OS is pitched as the entire Internet in your pocket…minus Flash. This works most of the time, but what if you just want to design a site or form that looks like a native iPhone App?
This is where iWebKit comes in. iWebKit is a free framework package for creating websites and applications that are optimized for the iPod Touch, iPhone & iPad. The bulk of the framework is CSS3 which can work its magic to makeover any dreadful site and make it look fresh.
I will be covering the web-form aspect of creating an optimized site, but iWebKit has many deeper features that can communicate directly with the OS. Its documentation is excellent, so dig around or check out the demo site on your iPhone to get inspiration.
When designing for the iPhone OS, you should use the iPhone simulator available in the SDK to get an idea of where your design is heading. You can also use Safari to get a pretty close representation, but nothing beats using a real physical device. It’s amazing how cool it feels and you really do get the impression it’s a native application.
Here is what the form looks like on the iPhone before we optimize it.
It’s pretty dull looking, to say the least. Below is the original HTML code being used. We’re going to get Apple-blood running through it and give it a makeover.
Select a Level of Education:<br />
<input type="submit" name="" value="Submit" />
This code needs to be in an HTML file in the same folder as the iWebKit framework. I called it
The first step is to add these lines between the
To create the top title bar we need to enter the following code immediately after the
If you load up the page in your iPhone simulator browser you will see this bar at the top.
Now we need to start our main content with the following
All the form fields will be inside of this
<div> and we won’t close it till the end of the form. The first form fields we want are the Name and Password fields.
Replace the original code:
Our Name and Password fields have now been transformed.
<ul> container represents the white box while the
<li> tag is to signify separate sections inside of the white box. You could also put each of these fields in their own
<ul> containers and they would look like two separate boxes. To save screen space, I group similar items together. Now lets replace those old fashioned radio buttons from the Gender question.
The radio buttons are changed for the better.
Next up are the checkboxes under the Favorite Food question.
Now instead of check boxes, we get those pretty on/off sliders we’re accustomed to inside the iPhone OS.
The textbox is pretty simple since it just creates a nice white box around the textbox.
Lets move on to the dropdown menus. Dropdowns always use the iPhone’s built-in method and help create the feeling of a native app.
Notice the arrow span class adds the down arrow to the right of the selection box.
As far as the form goes, all that’s left is the Submit button and to close the
Now close the content
<div> tag with the following:
Finally, we may want to put a footer at the bottom of our page. It’s nice to also support the iWebKit folks.
That’s it for the HTML portion. Two nice little touches you can do are for when someone adds the page to their home screen. When browsing the page, click the “+” button and select the Add to Home Screen option. You will see an icon that, by default, is a screenshot of the page. You can customize this by making your own 58×58 pixel image and referring to it in the
<head> section. Mine is named homescreen.png and I’ve already included the code at the beginning of the article.
Now when this page is added to the Home Screen, it will look and feel like a native app. Why not have a startup screen displayed while the page loads? iWebKit also has this feature and you simply need a 320×460 pixel image that again, is referenced in the
<head> section. I have called mine startup.png.
That’s it, we’re done! iWebKit has many other features that you should check out. You may get some inspiration for an app or at least look good to your boss when you pretty up that old form that’s been around for years. All the files used in this article are also attached for your viewing pleasure along with a short video walkthrough of this tutorial.
Project Files: iwebkit-tutorial-files.zip (94 KB, ZIP)