[转]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 ...
随机推荐
- BFS:HDU2054-A==B?(字符串的比较)
A == B ? Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- (洛谷)P1019 单词接龙
题目描述 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母,要求出以这个字母开头的最长的"龙"(每个单词都最多在"龙" ...
- webpack + babel + vue 环境设置
npm i webpack --save-dev npm install style-loader css-loader url-loader babel-loader sass-loader fil ...
- Effictive C++ 学习记录
这是前段时间看的书,整理到这里吧,以后查看也方便. 这些条款需要反复查看. 条款01:视C++为一个语言联邦 条款02:尽量用const.enum.inline替换#define 条款03:尽可能的使 ...
- 精通CSS高级Web标准解决方案(6、对表单与表格应用样式)
使用fieldset input[type="text"] { width:200px; } input:focus,textarea:focus{background:#ffc; ...
- structs2 对ActionContext valueStack stack context 的理解 图片实例
structs2 对ActionContext valueStack stack context 的理解 ActionConext : The ActionContext is the context ...
- 通过 purge_relay_logs 自动清理relaylog
使用背景 线上物理备份任务是在从库上进行的,xtrabackup会在备份binlog的时候执行flush logs,relay-log会rotate到新的一个文件号,导致sql thread线程应用完 ...
- php开启子进程处理
$pageNum = ceil($totalNum/$pageSize); for($page=1;$page<=$pageNum;$page++){ $this->o_pcntl-> ...
- Redis实现缓存,你应该懂的哪些思路!
场景一:类似于微博,实现关注和被关注功能. 思路: 对每个用户使用两个集合类型键,用来存储关注别人的用户和被该用户关注的用户.当用户A关注用户B的时候,执行两步操作: sadd user:A B sa ...
- 解决云服务器ECS,windows server 2012不能安装SQL Server 2012,不能安装.NET Fromework 3.5
在云服务器上安装SQL Server 2012 时出现“启用windows功能NetFx3时出错”的问题:NetFx3指的是.NET Framework 3.5,SQL Server 2012数据库系 ...