我有一个UITableViewCell的自定义子类,并设置了一些约束.
问题是当我尝试更改一个视图的大小时:
CGRect frm = CGRectMake(0, 0, someValue, 30);
cell.indentView.frame = frm;
Run Code Online (Sandbox Code Playgroud)
依赖于cell.indentView宽度的其他视图根本不会移动.
可能是这样的?
此代码将起作用:
// enumerate over all constraints
for (NSLayoutConstraint *constraint in cell.indentView.constraints) {
// find constraint on this view and with 'width' attribute
if (constraint.firstItem == cell.indentView && constraint.firstAttribute == NSLayoutAttributeWidth)
{
// increase width of constraint
constraint.constant = someValue;
break;
}
}
Run Code Online (Sandbox Code Playgroud)