Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

estupefactika

macrumors member
Original poster
Feb 16, 2009
47
0
Alcobendas (Madrid)
Hi, I would like to do something similar to press release detail like New York Times or Usa Today.

I want a scroll with a title, an image and a webview with HTML.

I have done this for now:

Code:
	scroll=[[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
	//Títle
	
	CGRect tit =CGRectMake(0.0f, 0.0f, 320.f, 50.0f);
	UILabel *title=[[UILabel alloc] initWithFrame:tit];
	title.text=[itemNew objectForKey:@"title"];	
	title.numberOfLines = 2;
	title.font=[UIFont fontWithName:@"Helvetica" size:16.0f];
	title.textColor=[self getColor:@"00336E"];
	[scroll addSubview:title];
	[title release];	
	
	//Message body
	webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0f, 50.0f, 320.0f, 480.0f)];
	[self.webView setScalesPageToFit:NO];		
	NSString *cuerpo=[itemNew objectForKey:@"body"];	
	[webView loadHTMLString:cuerpo baseURL:nil];
	[scroll addSubview:webView];
	[webView release];	
		
	self.view=scroll;	
	[scroll release];

But my title is fixed, only webview does scroll, I would like together (title, image,webview) do scroll in the same layer.

How Could I do it? Thanks
 

estupefactika

macrumors member
Original poster
Feb 16, 2009
47
0
Alcobendas (Madrid)
Yes thanks, but I have problems now sizing webView...

if I put setScalesPageToFit:YES, my HTML looks a lot smaller than I would like. Searching in google, Ive found this trick to optimize web site in Iphone:

Adding in head of my html:
<meta name="viewport" content="width=320"/>

Now it has a font size correct, it works, but my problem is with the height of webView. If its higher than 1200 or 1300px dont display all html ...

I have a method to calculate cgRect frame depending HTML string, UIFont family name, size..., it returns a frame to display my webView, but when height is bigger than 1300 px approximately falls.

Code:
webView = [[UIWebView alloc] initWithFrame:calcRect(html,[UIFont boldSystemFontOfSize:16],100,320.0f)];	
[webView loadHTMLString:html baseURL:nil];	
[scroll setContentSize:CGSizeMake(320.0f,webView.frame.size.height)];
[self.webView setScalesPageToFit:YES];

I would like to ask 2 doubts:
1) Has anyone had problems with webView so high? I have just read that UIView size is 1024px. This is the problem... How could I display the rest of my HTML when height is bigger than 1024px?

2) Is there an other way to calculate webView height according to content?

Thanks
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.