我在我的项目中使用 autolayout
,但有一种情况让我卡住了。我已经完成了 TableviewCell
的自定义 XIB
,但我想使用 Tableview
的默认原型(prototype)单元格来完成它。我的设计如下所示
现在在我的设计中,我选择 constraint
top to button 并给出如下标识符
在 Tableview
原型(prototype) cell
中,我无法给出导出。那么我如何访问带有标识符的 NSLayoutConstraint
。我通过网络搜索但没有找到
请帮助我。
谢谢
最佳答案
希望这对您有所帮助。
NSArray *constraints = [myView constraints]; // Here myView is a reference to the required UI component
int count = [constraints count];
int index = 0;
BOOL found = NO;
while (!found && index < count) {
NSLayoutConstraint *constraint = constraints[index];
if ( [constraint.identifier isEqualToString:@"topconstraint"] ) {
//save the reference to constraint
constraint.constant = yourValue;
found = YES;
}
index++;
}
也可以使用 Predicate 过滤掉:
constraints.filter{ $0.identifier == "MyIdentifierText"}.first { }
关于ios - 如何使用标识符将 NSLayoutConstraint 访问到 tableviewcell 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41374061/