Showing posts with label html. Show all posts
Showing posts with label html. Show all posts

Thursday, June 30, 2011

How to View HTML Source Code from UIWebView

While debugging a sudden Facebook iOS library defect (Blank Dialog presented), I needed to check the HTML code received from Facebook server. This is how to do it:

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
   NSLog(@"%@",
    [webView stringByEvaluatingJavaScriptFromString:
    @"document.body.innerHTML"]);
}
Let's hope Facebook will quickly fix their faulty server-side code - and next time do better testing before a release...

Friday, March 4, 2011

How to Center Image when Rotating UIWebView

What happens, when you rotate iPhone while your application shows embedded webpage with custom background graphics? Hopefully the application rotates, too, and hopefully the background image has been designed well (*).

Here is an example how to top center backgroung image while rotating. Please note that the image has been poorly designed ON PURPOSE. Can't make a point with well designed graphics :)

Tuesday, August 24, 2010

How to Show Text Left and Right in UIWebView

When you need to show text on same line at left and right in UIWebView, this is one way:
NSString *myHtml = [NSString stringWithFormat:
    @"<html><body>"
    "<span style='float:left'>%@</span>"
    "<span style='float:right'>%@</span>"
    @"</body></html>",
    @"I'm left", @"I'm right"];
   
[self.cellWebView loadHTMLString:myHtml baseURL:nil];
Can't use div, since it seems to force a linebreak by default.

Monday, August 23, 2010

How to Get Share Buttons into Blogger

Blogger supports Share Buttons - officially.

Unofficially you might have to do some manual tweaking to make it actually work: Solution: Blogger Share Buttons not showing up? and reverse style.

Monday, May 10, 2010

UIWebView with Custom Background Image

Taking UIWebView into use is pretty easy, customizing is a bit more complicated. Here's how you can define your own image as background.

NSString *myHtml = [NSString stringWithFormat:
                    @"<html><head>"
                    "<style type=\"text/css\">"
                    "body{"
                    "background-image:url(%@);"
                    "}"
                    ",</style>"
                    "</head>"
                    "<body>Hello world</body></html>", imgName];

// baseURL for background image, otherwise nil
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[self.myWebView loadHTMLString:myHtml baseURL:baseURL];

Tuesday, January 26, 2010

How to Show Source Code in Blogger

Amazing, but Blogger still doesn't seem to support presenting source code as-is. There are several tips how to do it yourself, for example "Adding Syntax Highlighting to Blogger" by Heisencoder. Unfortunately none of these ways are very simple.

For now I'll settle for non syntax colored plain code lines. I'll use "HTML-encode a String Online" tool to start with.

Good enough, right ROI.