//先来一个可行的小Demo程序:结合searchBar的google搜索

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UIWebViewDelegate,UISearchBarDelegate>{
UIWebView *webView;
UISearchBar *searchBar;
}
@end -(void)loadView{
[super loadView];
CGRect bounds = [[UIScreenmainScreen] applicationFrame]; //UISearchBar
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 0.0, bounds.size.width, 48.0)];
searchBar.delegate = self;
searchBar.placeholder = @"Google"; //提示字符
[self.view addSubview:searchBar]; webView = [[UIWebViewalloc] initWithFrame:CGRectMake(, , , )];
[webView setScalesPageToFit:YES]; //自动缩放页面以适应屏幕
[self.view addSubview:webView]; //连接到一个现有的窗口上 } -(void)searchBarSearchButtonClicked:(UISearchBar *)activeSearchBar{
NSString *query = [searchBar.text stringByReplacingOccurrencesOfString:@" "withString:@"+"];//将“ ”空格替换成“+”
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.google.com/search?q=%@",query]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];//链接网络地址
}

//2.用webview显示内容,高度自适应

//webview显示简介内容
UIWebView * webviewinfomationDetails = [[UIWebView alloc] initWithFrame:GRAPH_SIZE_INTRODUCETEXT];
webviewinfomationDetails.backgroundColor = [UIColor clearColor];
[webviewinfomationDetails loadHTMLString:remark baseURL:nil];
[webviewinfomationDetails setUserInteractionEnabled:NO];
[(UIScrollView *)[[webviewinfomationDetails subviews] objectAtIndex:] setBounces:NO];
[webviewinfomationDetails setScalesPageToFit:NO]; //yes:根据webview自适应,NO:根据内容自适应
[webviewinfomationDetails setDelegate:self];
[myScrollView addSubview:webviewinfomationDetails];
[webviewinfomationDetails release]; //另一种显示方式
//定义WebView显示内容
webviewinfomationDetails = [[UIWebView alloc] initWithFrame:GRAPH_SIZE_WEBVIEW];
[webviewinfomationDetails setScalesPageToFit:NO]; //大小自适应
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *base = [NSURL fileURLWithPath:path];
[webviewinfomationDetails loadHTMLString:remark baseURL:base];//链接url
[webviewinfomationDetails setUserInteractionEnabled:NO];//设置用户不可修改
[informationDetailsScroll addSubview:webviewinfomationDetails];
webviewinfomationDetails.delegate=self;
[webviewinfomationDetails release]; //webview委托 高度自适应
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
CGSize actualSize = [webView sizeThatFits:CGSizeZero];
CGRect newFrame = webView.frame;
newFrame.size.height = actualSize.height;
webView.frame = newFrame; CGSize newsize=CGSizeMake(, +webView.frame.size.height);
myScrollView.contentSize=newsize;
}

ios学习之UIWebView网页视图调整的更多相关文章

  1. ios学习之UIWebView网页视图

    转载于爱德凡的百度空间,地址:http://hi.baidu.com/aidfan/item/34a720866b33cbcdef083d37 UIWebView 使用详解 一.UIWebView加载 ...

  2. [Swift通天遁地]一、超级工具-(5)使用UIWebView(网页视图)加载本地页面并调用JavaScript(脚本)代码

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  3. [Swift通天遁地]一、超级工具-(4)使用UIWebView(网页视图)加载HTML和Gif动画

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  4. [转]IOS 学习笔记(8) 滚动视图(UIScrollView)的使用方法

    下面介绍pageControl结合ScrollView实现连续滑动翻页的效果,ScrollView我们在应用开发中经常用到,以g这种翻页效果还是很好看的,如下图所示: 通过这个例子,我们重点学习UIS ...

  5. iOS UI-UIPickerView(拾取器)、UIWebView(网页视图)和传值方式

    // // ViewController.m // IOS_0107_finalToolClass // // Created by ma c on 16/1/7. // Copyright (c) ...

  6. iOS:网页视图控件UIWebView的详解

    网页视图控件:UIWebView 功能:它是继承于UIView的,是一个内置的浏览器控件,以用来浏览从网络下载下来的网页或者本地上加载下来的文档. 枚举: //网页视图导航类型 typedef NS_ ...

  7. ios网络学习------4 UIWebView的加载本地数据的三种方式

    ios网络学习------4 UIWebView的加载本地数据的三种方式 分类: IOS2014-06-27 12:56 959人阅读 评论(0) 收藏 举报 UIWebView是IOS内置的浏览器, ...

  8. 【iOS系列】-UIWebView加载网页禁止左右滑动

    [iOS系列]-UIWebView加载网页禁止左右滑动 问题: 做项目时候,用UIWebView加载网页的时候,要求是和微信网页中打开的网页的效果一样,也即是只能上下滑动,不能左右滑动,也不能缩放. ...

  9. iOS学习笔记-精华整理

    iOS学习笔记总结整理 一.内存管理情况 1- autorelease,当用户的代码在持续运行时,自动释放池是不会被销毁的,这段时间内用户可以安全地使用自动释放的对象.当用户的代码运行告一段 落,开始 ...

随机推荐

  1. 解释#ifdef ALLOC_PRAGMA代码段的原理

    By default, the kernel loader will load all driver executables and any global data that you may have ...

  2. 网页QQ弹出

    <script language="javascript"> function cdyht(){ window.location.href='tencent://Mes ...

  3. git 服务器新建仓库 远程仓库

    Git 服务器搭建 上一章节中我们远程仓库使用了 Github,Github 公开的项目是免费的,但是如果你不想让其他人看到你的项目就需要收费. 这时我们就需要自己搭建一台Git服务器作为私有仓库使用 ...

  4. .NET中使用FastReport实现打印功能

    FastReport是功能非常强大的报表工具,在本篇文章中讲解如何使用FastReport实现打印功能. 一.新建一个窗体程序,窗体上面有设计界面和预览界面两个按钮,分别对应FastReport的设计 ...

  5. 在android程序中打开另一个应用程序

    Android 开发有时需要在一个应用中启动另一个应用,比如Launcher加载所有的已安装的程序的列表,当点击图标时可以启动另一个应用. 一般我们知道了另一个应用的包名和MainActivity的名 ...

  6. gson 设置多个别名SerializedName

    如图: @SerializedName(value = "orderDetail",alternate = {"orderDetail1","adve ...

  7. [maven] settings 文件 国内镜像站

    <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Soft ...

  8. mysql执行带外键的sql文件时出现mysql ERROR 1215 (HY000): Cannot add foreign key constraint的解决

    ERROR 1215 (HY000): Cannot add foreign key constraint 最近在建表时遇到了这个错误,然后找了下找到了解决办法,记录下: 本来是要建两张表: 1 2 ...

  9. 利用altium怎么生成PDF及怎么1:1打印文档

    画完板子之后,还要生成原理图PDF文档,供其他设计人员参考和指正. 上图红框标注的两个地方,分别用于打印预览设置和生成原理图PDF.那么若是生成原理图PDF文档,则选择smart PDF即可. 点击s ...

  10. 关于Unity中网格导航与寻路

    寻路思路 1.烘焙出地形数据,导航数据,区分哪些是路径,哪些是障碍物 2.给要寻路的角色添加寻路的组件,加好了以后就会有速度和目的地之类的参数设置 3.只要设置好目的地,角色就会根据烘焙好的地图自己走 ...