Home > iPhone SDK > Objective C: Show online image on iPhone

Objective C: Show online image on iPhone

By default the UIImageView control from the iPhone sdk does not allow us to load images from a specific url. In this case we do a little tryck and use a UIWebView.

- (void)loadImage:(NSString*)url frame:(CGRect)frame {
NSString* textHTML = @"
<!--
body {
background-color: transparent;
color: white;
}
-->
<img src="\" alt="" width="%0.0f" height="%0.0f" />
";
 
NSString* html = [NSString stringWithFormat:textHTML, url, frame.size.width, frame.size.height];
 
if(webView == nil) {
webView = [[UIWebView alloc] initWithFrame:frame];
[self.view addSubview:webView];
}
 
[webView loadHTMLString:html baseURL:nil];
}

Bookmark and Share
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Blogosphere News
  • LinkedIn
  • Live
  • MySpace
  • Tumblr
  • TwitThis
  • Yahoo! Buzz
  • StumbleUpon
  • Technorati