在 tableViewCell 中更改约束

change constraint inside tableViewCell

我需要更改 UITableViewCellUIView 的宽度约束。通常我会为约束创建一个 IBOutlet 但我该如何处理它,因为它是一个动态原型 tableView ?请推荐

谢谢!

您可以通过以下方式完成

  1. 通过动态创建新视图

    UIView *v=[[UIView alloc]init]; v.frame=CGRectMake(0, 0, 500, 250);

  2. 或通过标签访问视图或通过访问 -(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

    中的内容视图子视图

    UIView *v=[cell.contentView.subviews objectAtIndex:0]; v.frame=CGRectMake(0, 0, 500, 250);

希望对您有所帮助