Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
I have an embedded UIWebView in my app whose content size can vary a great deal. Before loading content into the view, I set the frame to some reasonable size; however, after the content is loaded, there can be a big gap between the web view and the view that comes after.
Is there some way to automatically resize the web view based on its content? I tried using UIView sizeToFit, but apparently UIWebView just uses the default (no-op) implementation.
- tried it with no lock, sizeThatFits called there returns exact same CGRect that was passed at creation time (I've used UIWebView alloc initWithFrame). Could you tell me more how did you managed to get the content height? Thanks in advance, as I'm completely confused. Have to put another view below the web view that may change size :(
sizeThatFits does seem to return something more useful IF the UIWebView was actually drawn (was part of a view that is on the screen). When I hold the UIWebView and do not install it into a parent view then the webViewDidFinishLoad is called, but the sizeThatFits is only the given frame.
I'm still working the best way to get a height from UIWebView too, this seems a common issue.
sizeThatFits does seem to return something more useful IF the UIWebView was actually drawn (was part of a view that is on the screen). When I hold the UIWebView and do not install it into a parent view then the webViewDidFinishLoad is called, but the sizeThatFits is only the given frame.
I'm still working the best way to get a height from UIWebView too, this seems a common issue.
I'm using Javascript to calculate it and it works very well. But first, the only thing you should do, is to preload any media inside HTML, like images. It can be done using Javascript to.
I know it's an older post, but since I got here looking for a fix I'll post here (it might help future visitors).
As long as the webview is created with a size larger then the size required to display its content then the solution posted here (sizeThatFits) will return the actual size of the webview. However, if the webview is created with a smaller size then the sizeThatFits will return the content size. I only tested it on 4.2, I hope it helps.
Replies
(from webViewDidFinishLoad) and using this size to resize the web view. This works.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeIn SDK 2, sizeThatFits returns the frame's size...
I think we should use the javascript approach:
I know... it is very ugly... :p
Hami.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI'm still working the best way to get a height from UIWebView too, this seems a common issue.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeAs long as the webview is created with a size larger then the size required to display its content then the solution posted here (sizeThatFits) will return the actual size of the webview. However, if the webview is created with a smaller size then the sizeThatFits will return the content size.
I only tested it on 4.2, I hope it helps.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome