UIWebView when you can not set a fixed height, you need to be based on the content of the Web page to adapt to the height, the reference code is as follows:
//
Viewcontroller.m
UIWebView highly Adaptive
//
Created by Mac on 16/3/18.
COPYRIGHT©2016 year Zmit. All rights reserved.
//
#import "ViewController.h"
@interface Viewcontroller () <uiscrollviewdelegate,uiwebviewdelegate>{
UIWebView *mywebview;
}
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
Do no additional setup after loading the view, typically from a nib.
Self.view.backgroundColor = [Uicolor Graycolor];
Mywebview = [[UIWebView alloc] Initwithframe:cgrectmake (0, [UIScreen mainscreen].bounds.size.width, 30)];
Mywebview.delegate = self;
MyWebView.scrollView.delegate = self;
Mywebview.scalespagetofit = yes;//Automatically scales the page to fit the screen
[Self.view Addsubview:mywebview];
Nsurl *url = [Nsurl urlwithstring:@ "http://www.111cn.net/"];
Nsurlrequest *request = [Nsurlrequest Requestwithurl:url];
[Mywebview Loadrequest:request];
}
#pragma mark-Agent method
-(void) Webviewdidfinishload: (UIWebView *) webview{
CGFloat webviewheight = [[WebView stringbyevaluatingjavascriptfromstring:@ "Document.body.offsetHeight"]floatvalue] ;
CGRect newframe = webview.frame;
NewFrame.size.height = Webviewheight;
Webview.frame = Newframe;
Reset the WebView contentsize
MyWebView.scrollView.contentSize = newframe.size;
If there are other controls underneath the WebView block, you can set its frame here by Mywebview
}
-(void) didreceivememorywarning {
[Super didreceivememorywarning];
Dispose of any of the can is recreated.
}
@end