Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-01-2009, 04:54 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 181
Post How to stretch the image to cover the whole UIWebView?

1. I get an image from a URL.
2. I want that image to stretch and cover the whole WebView.
3. I used different modes like a)ScaleToFill b)AspectFill c)AspectFit.
4. But its not stretching and covering the whole area.

Can someone help me plz?
wolverine is offline   Reply With Quote
Old 12-01-2009, 10:17 AM   #2 (permalink)
Registered Member
 
opetopic's Avatar
 
Join Date: Nov 2009
Location: Brooklyn, NY
Posts: 83
Default

A webview displays html, so you need to write html that does what you want. You could do something like:

<img src="/path/to/yourimage.jpg" width=100%" height="100%">
__________________
Opetopic
IsoWords (iTunes)
Twitter @opetopic
opetopic is offline   Reply With Quote
Old 12-01-2009, 10:57 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 181
Smile

But I am loading the image directly from a url like
Code:
[webView loadRequest:[NSURLRequest requestWithURL:imageUrl]]
. Here the imageUrl contains the URL that fetches the image. Can u show me how to modify the code plz?
wolverine is offline   Reply With Quote
Old 12-02-2009, 01:08 AM   #4 (permalink)
Registered Member
 
opetopic's Avatar
 
Join Date: Nov 2009
Location: Brooklyn, NY
Posts: 83
Default

Why not do:

Code:
NSString *html = @"<html><body><img src='http://www.domain.com/path/to/your/image.jpg' width='100%' height='100%'></body></html>";
[webView loadHTMLString:html baseURL:nil];
__________________
Opetopic
IsoWords (iTunes)
Twitter @opetopic
opetopic is offline   Reply With Quote
Old 01-11-2010, 05:42 PM   #5 (permalink)
Registered Member
 
pieter78's Avatar
 
Join Date: Apr 2009
Location: Maastricht, The Netherlands
Posts: 13
Default

Quote:
Originally Posted by opetopic View Post
Why not do:

Code:
NSString *html = @"<html><body><img src='http://www.domain.com/path/to/your/image.jpg' width='100%' height='100%'></body></html>";
[webView loadHTMLString:html baseURL:nil];
Thanks for the suggestion! I had the same problem, could not solve it. With your hint I got it to work, after a minor modification:

Code:
// Create URL string for image file location
NSString *imageName	 = [[NSBundle mainBundle] pathForResource:@"test_image" ofType:@"png"];
NSURL	 *imageURL	 = [NSURL fileURLWithPath: imageName];

// Create HTML string from image URL
// Width-value is arbitrary (and found experimental): 900 works fine for me
NSString *htmlString = @"<html><body><img src='%@' width='900'></body></html>";
NSString *imageHTML  = [[NSString alloc] initWithFormat:htmlString, imageURL];

// Load image in UIWebView
imageWebView.scalesPageToFit = YES;
[imageWebView loadHTMLString:imageHTML baseURL:nil];
If I set the image width property to 100%, it's too small - I don't understand why. When I do this AND turn off the UIWebView's scalesToFit property, then it works, but this means I cannot zoom in on the image (which I definitely want). So after a little experimenting I arbitrarily set the width to 900, and this works fine for what I want.

Thx!

Pieter
__________________
DigitalNeurosurgeon.com
pieter78 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 1,025
21 members and 1,004 guests
ADY, Alex_TNT, AragornSG, arfius, eggerr, fanarin, GENnick, janice23, jjaaxx44, Marckov85, markn, mikeirvingapps, nidie, OstinGames2011, premkumarmsc1, rrlemoine, sebasx, SoulRed12, Stut72, Sunny46, undeadlegion
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,488
Threads: 89,095
Posts: 380,135
Top Poster: BrianSlick (7,091)
Welcome to our newest member, Stut72
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:18 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0