02 Apr 2009 @ 2:11 PM 

The other day I was working on my iPhone application.  In the application I have a view.  This view creates a UIWebView.  I then proceed to load content from a webpage into the web view.

This works great.  I was then tasked with adding a bit of style to the view.

I started by creating all of the style in the webpage, but I quickly realized that this was causing the load to be a lot slower.  Instead I had to integrate the design into the view and simply display the content from the webpage in the design.

This was going pretty well until the webpage sat like a big white blob on top of my nice image.  I couldn’t let this be and had to find a solution, luckily it wasn’t to complicated.

To accomplish this, we need to do 2 things.  One, we need to update our UIWebView as follows (this code assumes you’ve already created a UIWebView called “webView”):

webView.opaque = NO;
webView.backgroundColor = [UIColor clearColor];

At first, I simply thought I could stop here based on my understanding of how background colors worked.  However, it was still showing up as white because my webpage itself had, by default, a white background as well.

In your HTML page that you, you need to apply the following style:

background-color: transparent;

This can be applied directly to the <body> tag or if you have a CSS file or inline CSS to the body {} element.

Now, if you compile your application, the webpage should get loaded without a white background.

  • Share/Bookmark

Other useful articles

Posted By: Jamie
Last Edit: 02 Apr 2009 @ 10:21 AM

EmailPermalink
Tags
Tags: , ,
Categories: iPhone


 

Responses to this post » (None)

 
Post a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


 Last 50 Posts
 Back
Change Theme...
  • Users » 14
  • Posts/Pages » 75
  • Comments » 231
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight