[转]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 ...
随机推荐
- 可怕的万圣节 Linux 命令
虽然现在不是万圣节,也可以关注一下 Linux 可怕的一面.什么命令可能会显示鬼.巫婆和僵尸的图像?哪个会鼓励"不给糖果就捣蛋"的精神? crypt 好吧,我们一直看到 crypt ...
- EventUtil处理js兼容性问题
var EventUtil={ addHandler:function(element,type,handler){ //添加事件 if(element.addEventListener){ elem ...
- php中foreach循环遍历二维数组
最近在用tp3.2框架,在查询的时候用到了select(),这条语句返回的是二维数组,所以在对返回的数据做处理时,遇到了些麻烦,百度了下foreach,终于用foreach解决了数据的筛选问题 (因为 ...
- tp3.2框架中使用volist输出混乱的一点发现
在tp框架中,volist真的是一样很好用的东西,但是要是不注意,用起来也会有问题的 在Controller层中,将数据assign到页面 $this->assign('vo',$news); ...
- 深入解析AJAX的原理
AJAX:Asynchronous JavaScript And Xml(异步的JS和XML) 同步:客户端发起请求>服务端的处理和响应>客户端重新载入页面(循环) 异步:客户端实时请求& ...
- callback回调函数【转】
请给作者点赞--> 原文链接 什么是回调函数? 我们绕点远路来回答这个问题. 编程分为两类:系统编程(system programming)和应用编程(application programmi ...
- Visual Studio-IIS Express 支持局域网访问配置
转自:http://www.itnose.net/detail/6132793.html 注意:本人测试后,发现个问题,不知是我个人的VS问题还是普遍的.就是将配置文件中的新增的节点注释后,会导致页面 ...
- Android设为系统默认的短信应用
要设为系统默认的短信应用首先要配置一下AndroidManifest.xml文件,添加下列: <!-- BroadcastReceiver that listens for incoming S ...
- 项目管理者必知:适用于仪表盘项目的7个优秀JavaScript库
仪表盘是用于目标或业务流程的视觉指示工具,也用于切割杂乱无章的数据,从而分割出要点的重要工具.它可以帮助评估信息并及时做出正确的决定,一款实时可视化的仪表盘通常由图标.测绘图.图形符号以及数据表格等组 ...
- github readme.md 添加图片
简要: 将图片放在仓库里面,在文件里链接它,最后 push 到 github 上. github 图片链接格式: (http://github.com/yourname/your-repository ...