【问题标题】:Set Constraint to UITableViewCell related to UiViewController将 Constraint 设置为与 UiViewController 相关的 UITableViewCell
【发布时间】:2016-03-17 09:03:23
【问题描述】:

我想添加 UITableViewCells 高度约束等于另一个名为标题视图的视图

在我的 SuperView 中,顶部有一个 HeaderView。我已将其高度限制设置为我的 superView 的 1/10。

我有一个 UITableView,其中有一个 UITableViewCell。 1.设置UITableViewCell的高度约束,与superview的比例为1/10。 或者 2.设置高度约束等于HeaderView。

我可以在 Interface Builder 上添加一个约束,从我的 UITableViewCell 到 Header View 或 superview?

【问题讨论】:

  • 不,你必须从代码中设置 rowHeight 属性
  • 您不能在 TableViewCell 和单元格外部的其他视图之间设置约束。您可以通过以编程方式设置约束来做到这一点。
  • 嘿@techlorr,我希望rowHeight 属性与屏幕尺寸成比例。那我该怎么办?
  • 您已经使用 HeaderView 进行了设置。将 rowHeight 设置为 HeaderView 的高度..
  • 你想让行高为屏幕高度的1/10吗? @CloyMonis

标签: ios iphone swift uitableview autolayout


【解决方案1】:

你可以像这样将行高设置为屏幕高度的1/10

tableView.rowHeight = UIScreen.mainScreen().bounds.height/10

让我知道这是否有效

【讨论】:

  • 愿原力与你同在。 @CloyMonis
【解决方案2】:

您不能为情节提要中的表格单元格或表格标题设置高度限制。 您可以使用以下函数将标题和表格单元格的高度设为超级视图的 1/10:

// For table header view

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {

    CGFloat height = <superview>.frame.size.height/10;
    return height;
}

// For table cell

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    CGFloat height = <superview>.frame.size.height/10;
    return height;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-05
    • 2015-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-06
    • 2014-11-09
    相关资源
    最近更新 更多