UIWebView problem with size adjustment when rotating device
I have a UIWebview in which a have a local html placed . When the ipad shifts, i rearange the elements so that the UIWebView is smaller/bigger after the case. The problem is that although when i sift and adjust the width, although the width is adjusted, the text isn't . The text is visible only in the webview's frame but it goes offscreen (some 开发者_如何学运维text is hidden, it continues to some point not being visible) . How can i adjust the webview content width ?
I have faced this problem and what i did to solve is like this ... create a mothod
-(void)reconfigureFrame
{
[_yourWebView loadHTMLString:[NSString stringWithFormat:@"<html><body style='background-color: transparent; width: 280px; margin: 0; padding: 0;color:black;'><div id='ContentDiv'>%@</div></body></html>",theStringToShow] baseURL:nil];
}
in webView:DidLoad delegate method do this
NSString *contentHeight = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('ContentDiv').offsetHeight"];
CGRect frame = [containtView frame];
//containtView holds webView
frame.size.height = [contentHeight floatValue] + 10;
[containtView setFrame:frame];
frame = [webView frame];
frame.origin.x = 10;
frame.origin.y = 5;
frame.size.width = containtView.frame.size.width - 2*frame.origin.x;
frame.size.height = [contentHeight floatValue];
[webView setFrame:frame];
and in didAutoRotate just call the first method
精彩评论