Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5982471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:05:31+00:00 2026-05-22T22:05:31+00:00

In a UITextView i can resize the height of the control to it’s content

  • 0

In a UITextView i can resize the height of the control to it’s content like this:

CGRect frame = textView.frame;
frame.size.height = textView.contentSize.height;
textView.frame = frame;

But i want to use an UIWebView instead in order to show rich text. The UIWebVie’s content is:

NSString *myDescriptionHTML = [NSString stringWithFormat:@"<html> \n"
                                  "<head> \n"
                                  "<style type=\"text/css\"> \n"
                                  "body {font-family: \"%@\"; font-size: %@; }\n"
                                  "</style> \n"
                                  "</head> \n"
                                  "<body>%@</body> \n"
                                  "</html>", @"helvetica",
                                  [NSNumber numberWithInt:12], @"yadayadayada..."];
[webView loadHTMLString:myDescriptionHTML baseURL:nil];

So the UIWebView contains nothing but plain text. How can i achieve result similar to the above UITextView code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:05:32+00:00Added an answer on May 22, 2026 at 10:05 pm

    Although in theory the JavaScript method provided

    - (void)webViewDidFinishLoad:(UIWebView *)webview
        CGRect oldBounds = [[self webview] bounds];
        CGFloat height = [[webview stringByEvaluatingJavaScriptFromString:@"document.height"] floatValue];
        [webview setBounds:CGRectMake(oldBounds.x, oldBounds.y, oldBounds.width, height)];
    }
    

    should work (and seems to work for most people), it just didn’t for me. I tried with a number of variation and it always returned a size that has nothing to do with the true content’s height. A one liner would come up with 260 or 244 height, for instance. Don’t know why (would love to know).

    SO i ended up doing as hinted in this answer:

    - (void)webViewDidFinishLoad:(UIWebView *)aWebView {
        CGRect frame = aWebView.frame;
        frame.size.height = 1;
        aWebView.frame = frame;
        CGSize fittingSize = [aWebView sizeThatFits:CGSizeZero];
        frame.size = fittingSize;
        aWebView.frame = frame;
    
        NSLog(@"size: %f, %f", fittingSize.width, fittingSize.height);
    }
    

    I think the JS way more elegant but hell, it doesn’t works for me and can’t figure out why, while this method worked out of the box.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Resizing UITextView to fit height of its content can be achieved like this: CGRect
How can I make a UITextView scrollable but not editable programmly?? I tried this:
Sorry I can't think of a good title for this but here' my situation:
The font size of text in a UITextView is dynamic, how can I determine
why can't I access .layer.borderWidth for this UITextView instance? (code attached) UITextView *v =
I have a UITextView, user can write maximum 160 character in the textView. How
I want to hide the keyboard after typing the content into the UITextView but
How can I mix objective-c objects (i.e UITextView) with pure c++ UI like DooleJump
I'd like to create a UITextView that you can tap anywhere within it and
How can I use uislider to control alpha in uitextview ? Please provide code.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.