UIWebView和UICollectionViewController

UIWebView和UICollectionViewController的使用

UIWebView

UIWebView是iOS内置的浏览器的控件, 可以浏览网页, 打开文档等 .系统自带的Safari浏览器就是通过UIWebView实现的, 能够加载html/htm, pdf, docx, txt等格式的文件.

    在iOS7之前, UILabel, UITextFiled 以及 UITextView 都在后台以某种方式使用 WebKit来进行文本布局和渲染.

    渲染 : 是CG的最后一道工序, 将所设计内容制作成最终效果图或者动画的过程 .

UIWebView的使用

1> 确定要访问的资源

NSURL *url = [NSURL URLWithString : @"http://www.baidu.com"];

    2> 建立网络请求

NSURLRequest *request = [NSURLRequest requestWithURL :url];

    3> UIWebView加载网络请求

[self.webView loadRequest : request];

UIWebView - 实现百度搜索

1-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar 2{ 3    NSString *str = searchBar.text; 4     5    // 1. 判断是否以http开头,如果没有则用百度搜索 6    if (![str hasPrefix:@"http://"]) { 7        str = [NSString stringWithFormat:@"http://m.baidu.com/s?word=%@", str]; 8    } 9     10    // 2. 在URL中,如果包含中文字符串,需要将字符串转换为带百分号的格式 11    NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 12}

UIWebView - 前进后退

1#pragma mark - UIWebView代理方法 2-(void)webViewDidFinishLoad:(UIWebView *)webView 3{ 4    self.goBackButton.enabled = self.webView.canGoBack; 5    self.goForwardButton.enabled = self.webView.canGoForward; 6}

UIWebView优缺点:

优点:

1> 使用简单 ; NSURL确定要访问的网络资源, NSURLRequest建立网络请求;

2> 能够方便的展现丰富的页面内容 ;

3> 在开发中, 通常遇到不方便排版的内容, 会考虑选择UIWebView .

缺点:

1> 以HTML为基础的页面方式, 交互相对单一, 局限性大 ;

2> 编辑排版HTML页面同样需要花费人力.

UICollectionViewController的使用

1> 注册cell(告诉collectionView将来创建怎样的cell) .

[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"product"];

    2> 从缓存池中取出cell

1-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 2{ 3  UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"product" forIndexPath:indexPath]; 4    return cell; 5}

3> 重写init方法, 创建布局参数

1-(id)init 2{ 3    // 1.流水布局 4      UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; 5    // 2.每个cell的尺寸 6      layout.itemSize = CGSizeMake(100, 100); 7    return [super initWithCollectionViewLayout:layout]; 8}

UICollectionViewFlowLayout

    UICollectionViewFlowLayout 称为 "流水布局", 用来约束cell的显示 ;

常见属性:

1// cell的尺寸  2@property (nonatomic) CGSize itemSize; 3// cell之间的水平间距  4@property (nonatomic) CGFloat minimumInteritemSpacing; 5// cell之间的垂直间距  6@property (nonatomic) CGFloat minimumLineSpacing; 7// 四周的内边距  8@property (nonatomic) UIEdgeInsets sectionInset;
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

UIWebView长按保存图片和识别图片二维码的实现方案(使用缓存)

0x00需求:长按识别UIWebView中的二维码,如下图长按识别二维码0x01方案1:给UIWebView增加一个长按手势,激活长按手势时获取当前UIWebView的截图,分析是否包含二维码。核心代码:略优点:流程简单,可以快速实现。不足:无法实现保存UIWebView中图片,如果当前We

UIWebView和UICollectionViewController - HelloWorld