的UITableViewCell +动态高度+自动布局 [英] UITableViewCell + Dynamic Height + Auto Layout

查看:202
本文介绍了的UITableViewCell +动态高度+自动布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从这个伟大的答案来了:<一href=\"http://stackoverflow.com/questions/18746929/using-auto-layout-in-uitableview-for-dynamic-cell-layouts-variable-row-heights\">Using自动布局中的UITableView动态单元布局和放大器;可变行高度

I came from this great answer: Using Auto Layout in UITableView for dynamic cell layouts & variable row heights

我实现了在这个问题的答案所描述的东西,但我有一点不同的情景面对的问题。我有没有一的UILabel 而是我的动态列表的UILabel 秒。

I've implemented the things described in that answer but I'm facing with a little different scenario. I haven't one UILabel but instead I have a dynamic list of UILabels.

我创建显示的表视图看起来应该有些不同情形的图片:

I've created an image showing some different cases of what the table view should look:

目前回购的当前状态的细胞不垂直增长以适应单元格的内容查看

At the current state of the repo the cell doesn't grow vertically to fit the cell's contentView.

更新

REPO: https://github.com/socksz/DynamicHeightCellAutoLayout

如果您尝试从回购获得项目并运行它,你可以看到什么是我所说的问题。我不能得到什么缺少让它工作。

If you try to get the project from the repo and run it, you can see exactly what is the problem I'm referring. I can't get what is missing for let it works.

推荐答案

这里的问题是您正在使用的第三方组件,FXLabel,不与任何围绕在其中表视图或自动布局code的。适当[intrinsicContentSize] 方法,然后再调用 - - 为了支持自动布局,UIView的定制类必须实现 [invalidateIntrinsicContentSize] 当有些变化了。

The problem here is with the third party component you are using, FXLabel, not with any of the code around table views or Auto Layout in them. In order to support Auto Layout, custom subclasses of UIView must implement the -[intrinsicContentSize] method appropriately, and then call -[invalidateIntrinsicContentSize] when something changes it.

在这种情况下,FXLabel似乎依赖于它的超类的实施(的UILabel),用于上述方法中,和自的UILabel没有被设计用于处理可变行距在于FXLabel实现它的方法,它不知道正确的intrinsicContentSize返回,因此,自动布局的计算是错误的(在这种情况下,由于固有含量太小)。请查看这个优秀obcj.io文章了解详情。

In this case, FXLabel appears to be relying on its superclass implementation (UILabel) for the above methods, and since UILabel was not designed to handle variable line spacing in the way that FXLabel implements it, it doesn't know the correct intrinsicContentSize to return, and therefore the Auto Layout calculations are wrong (in this case, since the intrinsic content size is too small). Check out the "Enabling Custom Views for Auto Layout" section of this excellent obcj.io article for more details.

现在的好消息是,作为iOS 6后,你应该能够做到这一点在标准的UILabel使用归因字符串。查看堆栈溢出回答这里

Now the good news is that as of iOS 6, you should be able to accomplish this using an attributed string in a standard UILabel. Check out the Stack Overflow answer here.

如果由于某种原因,你真的喜欢FXLabel,也许你可以打开GitHub的项目的问题(或试图修复它自己,并提交pull请求)。

If for some reason you really like FXLabel, perhaps you could open an issue on the GitHub project (or try and fix it yourself and submit a pull request).

这篇关于的UITableViewCell +动态高度+自动布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆