【问题标题】:tableviewcell using AutoLayout update constraint programmatically以编程方式使用 AutoLayout 更新约束的 tableviewcell
【发布时间】:2016-07-18 10:09:13
【问题描述】:

我有一个使用 Autolayout 的自定义 tableviewcell,在 xib 文件中设计。

设计:

CustomTableViewCell.h: @property (weak, nonatomic) IBOutlet UIView *customView; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraintRatio;

在表格视图中可以正常工作。

我想做的是在 tableviewcell 显示之前以编程方式更新 CustomView 的 Ratio。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ CustomTableViewCell *customCell = [self.mainTableView dequeueReusableCellWithIdentifier:@"customCell"]; customCell.constraintRatio.constant = 2; [customCell setNeedsUpdateConstraints]; [customCell setNeedsLayout]; [customCell layoutIfNeeded]; return customCell; }

但此后单元格的比率仍为 1。 我做错了什么或者我错过了什么?感谢您的任何建议。

【问题讨论】:

    标签: ios autolayout constraints tableviewcell


    【解决方案1】:

    问题解决了。

    我误用了customCell.constraintRatio.constant。应该是乘数。

    multiplier 是只读的。所以完成我的工作的唯一方法是删除约束并添加新的约束

    这样做之后,一切正常。

    参考: auto layout modify multiplier of constriaint programmatically

    【讨论】:

      猜你喜欢
      • 2018-11-25
      • 1970-01-01
      • 1970-01-01
      • 2014-01-05
      • 2015-07-15
      • 2021-12-20
      • 2015-06-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多