【问题标题】:move UILabel and UIImageVIew on UITableviewcell with autoLayout使用 autoLayout 在 UITableviewcell 上移动 UILabel 和 UIImageVIew
【发布时间】:2015-01-14 14:15:44
【问题描述】:

我有一个文件夹的表格视图,当用户点击文件夹时,它会显示子文件夹,名称移动 20 像素以获得“子图形效果”。现在,切换到Autolayout,我无法使用代码以编程方式移动UIView 的元素:

- (void) configureView {

    if (self.cellMode != NVCellModeSelect) {
        [self setBackgroundColor:[NVGlobals homeCellBackgroundColor]];
        //Indenting label
        CGRect r = self.titleLabel.frame;
        r.origin.x = kLabelsInitialX + self.item.level*10;
        self.titleLabel.frame = r;

        //Indenting folder
        r = self.thumbnail.frame;
        r.origin.x = kFolderInitialX + self.item.level*10;
        self.thumbnail.frame = r;

        //Indent triangle
        r = self.triangleIcon.frame;
        r.origin.x = kTriangleInitialX + self.item.level*10;
        self.triangleIcon.frame = r;
    }
} 

但现在它似乎不起作用。如何使用 autoLayot 以编程方式在 UITableViewCell 中移动元素?

【问题讨论】:

标签: ios iphone cocoa-touch autolayout


【解决方案1】:

有两种方法可以做到这一点:

  1. 当单元格处于缩进状态时,您需要保留对每个子视图的前导约束的引用并调整它们的 constant 值。如果单元格被重复使用或未缩进,请记住将它们设置回默认值。

  2. 使用tableView:indentationLevelForRowAtIndexPath: 为您完成大部分繁重的工作。

【讨论】:

  • 两者都是很好的建议,但 #2 是正确的方法。
  • 我已经读过 tableView:indentationLevelForRowAtIndexPath: 在 iOS8 中无法使用自定义 UiTableCell。对吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-01
  • 1970-01-01
  • 2015-05-17
  • 1970-01-01
  • 2016-03-18
  • 1970-01-01
相关资源
最近更新 更多