UIScroll with uilabel, image and webview

Discussion in 'iPhone/iPad Programming' started by estupefactika, Mar 9, 2009.

  1. macrumors member

    Joined:
    Feb 16, 2009
    Location:
    Alcobendas (Madrid)
    #1
    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
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Instantiate a UIScrollView and then add your three elements as subviews of the scrollview.
     
  3. thread starter macrumors member

    Joined:
    Feb 16, 2009
    Location:
    Alcobendas (Madrid)
    #3
    Yes, I did this before. My scroll didnt have a height and by this didnt work. Now yes, thanks
     
  4. thread starter macrumors member

    Joined:
    Feb 16, 2009
    Location:
    Alcobendas (Madrid)
    #4
    Now, I need to set the height to the UIScrollView. It must to be equal to my WebView HTML height. How could I calculate the height of my webview?
     
  5. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    webView.frame.size.height?
     
  6. thread starter macrumors member

    Joined:
    Feb 16, 2009
    Location:
    Alcobendas (Madrid)
    #6
    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
     

Share This Page