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 :)
Showing posts with label UIWebView. Show all posts
Showing posts with label UIWebView. Show all posts
Friday, March 4, 2011
How to Center Image when Rotating UIWebView
Labels:
html,
loadRequest,
NSBundle,
NSURL,
NSURLRequest,
shouldAutorotateToInterfaceOrientation,
UIViewController,
UIWebView,
viewDidLoad,
webKit
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:Can't use div, since it seems to force a linebreak by default.
@"<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];
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];
Thursday, February 25, 2010
How to Disable UIWebView Selection
You could do this by running a short javaScript line at webViewDidFinishLoad, but I find this more elegant: define UIWebView properties in CSS.
As a bonus I left there also how to disable link selection popup.NSString *myHtml = [NSString stringWithFormat: @"<html><head>" "<style type=\"text/css\">" // Disable Open/Copy/Cancel alert with long link selection "* {" "-webkit-touch-callout: none;" // Disable selection/Copy of UIWebView "-webkit-user-select: none;" "}" ",</style>" "</head><body>%@</body></html>", message.body]; [myWebView loadHTMLString:myHtml baseURL:nil];
Labels:
CSS,
iphone,
javaScript,
NSString,
UIWebView
Wednesday, February 10, 2010
How to Make UIWebView Open target="_blank" Links
There are several ways to do this, here's mine.
Possible advantage: reduces size of HTML document.NSString *js = @"\ var a = document.getElementsByTagName('a');\ for (var i=0; i<a.length; i++) {\ a[i].removeAttribute('target');\ }\ "; [self.myWebView stringByEvaluatingJavaScriptFromString:js];
Subscribe to:
Posts (Atom)