-(void)setupView{ // 代码方式实现自动布局 VFL // 创建一个Tableview; UITableView *tableView = [[UITableView alloc] init]; //tableView.backgroundColor = [UIColor redColor]; tableView.delegate = self; #warning 代码实现自动布局,要设置下面的属性为NO tableView.translatesAutoresizingMaskIntoConstraints = NO; [self.view addSubview:tableView]; self.tableView = tableView; // 创建输入框View WCInputView *inputView = [WCInputView inputView]; inputView.translatesAutoresizingMaskIntoConstraints = NO; [self.view addSubview:inputView]; // 自动布局 // 水平方向的约束 NSDictionary *views = @{@"tableview":tableView, @"inputView":inputView}; // 1.tabview水平方向的约束 NSArray *tabviewHConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[tableview]-0-|" options:0 metrics:nil views:views]; [self.view addConstraints:tabviewHConstraints]; // 2.inputView水平方向的约束 NSArray *inputViewHConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[inputView]-0-|" options:0 metrics:nil views:views]; [self.view addConstraints:inputViewHConstraints]; // 垂直方向的约束 NSArray *vContraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-64-[tableview]-0-[inputView(50)]-0-|" options:0 metrics:nil views:views]; [self.view addConstraints:vContraints]; self.inputViewConstraint = [vContraints lastObject]; NSLog(@"%@",vContraints); }