auto uiLabel & 的 iphone 代码字体更改时 uiTableViewCell 调整大小?
有人可以总结一下 Objective-C 代码的关键部分来帮助解决这个问题吗?
目标 - 在用户更改字体大小后自动调整 UITableView 的大小。因此,如果用户增加或减少字体,则 (a) uiLabel 高度应更改以确保它们很好地包含文本,并且 (b) uiTableViewCell 高度也应调整。
假设是:
- UITableView 已通过扩展 创建自定义单元格视图 - 即在 NIB 中创建一个新视图 内容视图的表单 UITableView 单元格
- 每个自定义 单元格有四个 UILabel,它们形成 2 x 2 的 UILabels 图案 - 即两个 在顶行,两个在底行,
- 以便用户增加字体 的水平间距 UILabels 将保持不变, 但是标签高度会 所以我假设
我将包括挑战/问题(并希望通过某人可以发布的一些示例代码来回答)
- 这里的起点是 InterfaceBuilder 中已经布局的自定义 UITableViewCell 可以吗? (或者解决方案是否要求它完全以编程方式构建)?
- 如何计算标签的高度?这只是使用 NSString 方法“sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:”吗?我需要添加边距等吗?
- 如何以编程方式动态增加标签的高度 - 您使用哪种方法来执行此操作?如何改变高度本身
- 如何确保当顶部的 UILabel 展开时增长,它会自动下推第二行的 UILabel?这种情况是默认发生的还是有特定的属性/设置来确保这种情况发生。
- 在发生上述情况后,如何自动增加 TableViewcell 的高度。使用哪种方法执行此操作,以及如何以编程方式执行增加和删除操作?重画。
希望这是有道理的。
谢谢
Can someone summarise the key pieces of objective-c code that would assist in solving this.
Objective - Autoresize a UITableView after a user changes the font size. Therefore if the user increases or descreases font both the (a) uiLabel heights should change to ensure they nicely include text, and (b) uiTableViewCell heights should also adjust.
Assumption is that:
- UITableView has been extended via
creation of a custom cell view -
i.e. create a new view in a NIB that
forms for the content view of the
UITableView cells - each custom
cell has four UILabel's which form a
2 x 2 patter of UILabels - i.e. two
on top line and two on bottom line - so as the user increases the font
the horizontal spacing of the
UILabels would remain the same,
however the label heights would
change
So I assume the challenge / questions I have would include (and hopefully be answered by some sample code that someone can post)
- Is it OK that the starting point here is an already laid out custom UITableViewCell in InterfaceBuilder? (or does the solution require it is constructed totally programmatically)?
- How to calculate the heights the label's should be? Is this just with the NSString method "sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:", and do I need to add addition for margins etc?
- How programmatically to increase the height of the labels dynamically - in which method do you do this & how to change the height itself
- How to ensure that when UILabel at the top is expanded & grows, that it automatically pushes down the UILabel on the 2nd row? Does this happen by default or is there a specific property/setting you have to you to ensure this hapens.
- How to then automatically increase the height of the TableViewcell, after the above has occurred. Which method to do this in, and how programmatically to perform the increase & redraw.
Hope this makes sense.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要使 UILabel 的高度与您的目标字体相匹配,请使用
NSString
的sizeWithFont
函数。您可能遇到的问题是文本是否水平不适合您定义的边界。如果您希望字体相应缩小,请打开调整标志并设置如下所示的最小值。
To get the UILabel's height to match your target font, you use the
sizeWithFont
function ofNSString
.The problem you may run into is if the text doesn't fit horizontally in the bounds you've defined. If you want the font to downsize accordingly, turn on the adjustment flag and set a min like this.