最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
ios开发之UIWebView自适应高度例子
时间:2022-06-25 23:39:23 编辑:袖梨 来源:一聚教程网
UIWebView使用时当无法确切的设置一个固定的高度时,就需要根据网页内容来自适应高度了,参考代码如下:
//
// ViewController.m
// UIwebView高度自适应
//
// Created by mac on 16/3/18.
// Copyright © 2016年 ZMIT. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
UIWebView *myWebView;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor grayColor];
myWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 100, [UIScreen mainScreen].bounds.size.width, 30)];
myWebView.delegate = self;
myWebView.scrollView.delegate = self;
myWebView.scalesPageToFit = YES;//自动对页面进行缩放以适应屏幕
[self.view addSubview:myWebView];
NSURL *url = [NSURL URLWithString:@"https://www.111cn.net/"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:request];
}
#pragma mark - 代理方法
-(void)webViewDidFinishLoad:(UIWebView *)webView{
CGFloat webViewdocument.body.offsetHeight"]floatValue];
CGRect newFrame = webView.frame;
newFrame.size.height = webViewHeight;
webView.frame = newFrame;
//重新设置webView的contentSize
myWebView.scrollView.contentSize = newFrame.size;
//如果WebView块下面还有其他的控件,可在此处根据myWebView设置其frame
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
相关文章
- 新三国志曹操传马超无双试炼四通关攻略 12-15
- 俄罗斯YANDEX引擎官网入口-免登录直达Yandex首页 12-15
- 漫蛙ManWa在线免费阅读入口_漫蛙ManWa官方网页版一键直达 12-15
- 逃离鸭科夫仓库区地窖在哪 仓库区地窖入口位置详情 12-15
- 光与影33号远征队熙艾尔bd玩法:熙艾尔毕业装备与加点思路介绍 12-15
- 漫蛙网页版免费入口进不去-漫蛙网页版最新免费版一键直达 12-15