【问题标题】:Dynamic height for same content in UITabelviewcell using autolayout programatically以编程方式使用自动布局的 UITableviewcell 中相同内容的动态高度
【发布时间】:2016-05-09 05:41:28
【问题描述】:

我正在创建自定义 UITableViewCell 并以编程方式添加约束。但是我的相同文本没有在标签中调整,导致随机单元格的高度不同。我查看了各种教程并访问了其他堆栈问题的答案,但无法解决我的问题。

据我了解,这是左右标签之间的优先级问题。我在设置约束时也添加了这一行。

[righSideLabel setContentCompressionResistancePriority:950 forAxis:UILayoutConstraintAxisHorizontal];

【问题讨论】:

  • 不要发布项目的链接。相反,只需使用与问题相关的代码来更新您的问题。
  • - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewAutomaticDimension; } - (CGFloat)tableView:(UITableView *)tableViewestimateHeightForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewAutomaticDimension; }
  • 请在你的 .m 文件中添加这两个方法
  • 您是否尝试返回heightForRowAtIndexPath 中的高度?
  • @rmaddy 代码在多个类中,我将尝试添加

标签: ios objective-c uitableview autolayout


【解决方案1】:

您可以将 rowHeight 属性设置为 UITableViewAutomaticDimension 并将约束放在 Cell 的 Label 上并设置estimatedRowHeight 并且不要使用 heightForRowAtIndexPath strong> 方法。记住尝试放置 top、bottom、leading 和 trailing 约束。

【讨论】:

    猜你喜欢
    • 2014-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-09
    • 1970-01-01
    • 1970-01-01
    • 2014-08-02
    • 2017-04-07
    相关资源
    最近更新 更多