[转]iOS8 自动调整UITableView和UICollectionView布局
转自:http://www.cocoachina.com/industry/20140825/9450.html

- UIFontTextStyleHeadline
- UIFontTextStyleBody
- UIFontTextStyleSubheadline
- UIFontTextStyleFootnote
- UIFontTextStyleCaption1
- UIFontTextStyleCaption2


- - tableView:estimatedHeightForRowAtIndexPath:
- - tableView:estimatedHeightForHeaderInSection:
- - tableView:estimatedHeightForFooterInSection:
- import UIKit
- class DynamicCell: UITableViewCell {
- required init(coder: NSCoder) {
- super.init(coder: coder)
- if textLabel != nil {
- textLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline)
- textLabel.numberOfLines = 0
- }
- if detailTextLabel != nil {
- detailTextLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody)
- detailTextLabel.numberOfLines = 0
- }
- }
- override func constraints() -> [AnyObject] {
- var constraints = [AnyObject]()
- if textLabel != nil {
- constraints.extend(constraintsForView(textLabel))
- }
- if detailTextLabel != nil {
- constraints.extend(constraintsForView(detailTextLabel))
- }
- constraints.append(NSLayoutConstraint(item: contentView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.GreaterThanOrEqual, toItem: contentView, attribute: NSLayoutAttribute.Height, multiplier: 0, constant: 44))
- contentView.addConstraints(constraints)
- return constraints
- }
- func constraintsForView(view:UIView) -> [AnyObject]{
- var constraints = [NSLayoutConstraint]()
- constraints.append(NSLayoutConstraint(item: view, attribute: NSLayoutAttribute.FirstBaseline, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.Top, multiplier: 1.8, constant: 30.0))
- constraints.append(NSLayoutConstraint(item: contentView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.GreaterThanOrEqual, toItem: view, attribute: NSLayoutAttribute.Baseline, multiplier: 1.3, constant: 8))
- return constraints
- }
- }
- self.tableView.estimatedRowHeight = 44




- - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
- {
- CGRect oldBounds = self.collectionView.bounds;
- if (CGRectGetWidth(newBounds) != CGRectGetWidth(oldBounds)) {
- return YES;
- }
- return NO;
- }
- invalidateItemsAtIndexPaths:
- invalidateSupplementaryElementsOfKind:atIndexPaths:
- invalidateDecorationElementsOfKind:atIndexPaths:
- invalidatedItemIndexPaths
- invalidatedSupplementaryIndexPaths
- invalidatedDecorationIndexPaths
- shouldInvalidateLayoutForPreferredLayoutAttributes:withOriginalAttributes:
- invalidationContextForPreferredLayoutAttributes:withOriginalAttributes:
[转]iOS8 自动调整UITableView和UICollectionView布局的更多相关文章
- iOS 8自动调整UITableView和UICollectionView布局
本文转载自:http://tech.techweb.com.cn/thread-635784-1-1.html 本文讲述了UITableView.UICollectionView实现 self-siz ...
- UITableView和UICollectionView的Cell高度的几种设置方式
UITableViewCell 1.UITableView的Cell高度默认由rowHeight属性指定一个低优先级的隐式约束 2.XIB中可向UITableViewCell的contentView添 ...
- UITableView、UICollectionView行高/尺寸自适应
UITableView 我们都知道UITableView从iOS 8开始实现行高的自适应相对比较简单,首先必须设置estimatedRowHeight给出预估高度,设置rowHeight为UITabl ...
- RumTime实践之--UITableView和UICollectionView缺省页的实现
有关RunTime的知识点已经看过很久了,但是一直苦于在项目中没有好的机会进行实际运用,俗话说"光说不练假把式",正好最近在项目中碰到一个UITableView和UICollect ...
- UITableView和UICollectionView的方法学习一
参考资料 UITableView UICollectionView UICollectionViewDataSource UICollectionViewDelegate UICollectionVi ...
- UItableView嵌套UICollectionView
首先我们需要继承一下UITableView并且遵守<UITableViewDelegate,UITableViewDataSource,UICollectionViewDataSource,UI ...
- iOS8中 UITableView section 分区头部视图不显示
最近自己使用了UITableView写了一个通讯录,但是在编写过程还算顺利,但是后来测试的时候,发现在iOS8中TableView的分区头不能正常显示,使用 - (NSString *)tableVi ...
- iOS中UITableView和UICollectionView的默认空态页
项目中想实现空态页风格统一控制的效果,就封装了一个默认空态页,使用的技术点有:1 方法替换 ,2 给分类(Category)添加属性. 我们知道,扩展(extension)可以给类添加私有变量和方法. ...
- UITableVIew与UICollectionView带动画删除cell时崩溃的处理
UITableVIew与UICollectionView带动画删除cell时崩溃的处理 -会崩溃的原因是因为没有处理好数据源与cell之间的协调关系- 效果: tableView的源码: ModelC ...
随机推荐
- vue.js devtools安装
在调试的时候chrome会提示安装vue devtools,我以为是要在chrome的程序商店直接安装,但是国内对谷歌的和谐,无法访问谷歌商店内容 官方有源代码,可以下载下来自行编译安装 官方地址:h ...
- 使用VUE开发
<一>VUE的开发分两种,一种是直接在HTML文件中使用,一种是VUE文件的形式开发 1,首先我们先让 HTML 文件支持 VUE 的语法指令提示 2,File -> Setting ...
- 常用模块之 re shutil configparser hashlib xldt和xlwd
shutil 高级文件处理模块 封装的更简单了 主要是文件的复制,移动,压缩解压缩 需要保证目标文件已经存在shutil.copymode('test.txt','testcopy4.txt') 压缩 ...
- python3 包的发布
发布流程大概如下 1. 首先需要有一个python包,就是一个文件夹,但是此文件夹下面有__init__.py文件,里面内容是 现在要发布包TestMsg,这就是一个python包.在同级目录下新建s ...
- Codeforces Round #461 (Div. 2) B. Magic Forest
B. Magic Forest time limit per test 1 second memory limit per test 256 megabytes Problem Description ...
- Sublime Text配置python以及快捷键总结
1.打开Tools > Build System > New Build System.. 2.点击New Build System后,会生成一个空配置文件,在这个配置文件内覆盖配置信息, ...
- 后缀数组的使用心得——POJ2774 最长连续公共子串
对于这道题,将两个字符串直接合并成为一个字符串,分别记录连个字符串结束的位置. 首先,应用黑暗圣典的模板,我们可以顺利得到height,rank,sa三个数组. 之后直接扫描1-n所有的位置,选出来一 ...
- loj2063 「HAOI2016」字符合并
ref #include <iostream> #include <cstring> #include <cstdio> using namespace std; ...
- 图说不为人知的IT传奇故事-1-计算机新生
此系列文章为“图说不为人知的IT传奇故事”,各位大忙人可以在一分钟甚至几秒内了解把握整个内容,真可谓“大忙人的福利”呀!!希望各位IT界的朋友在钻研技术的同时,也能在文学.历史上有所把握.了解这些故事 ...
- Windows核心编程小结1
这本书绝对经典,看看定会增加不少知识.当然这本书有很多东西比<Windows程序设计第五版>中的更加详细. 1.Unicode:宽字节字符集 这是一个国际的字符标准,16位,最大可支持65 ...