答案 0 :(得分:0)
怎么样......
@interface CustomViewController ()
@property (strong, nonatomic) UITableView *tableView;
@end
@implementation CustomTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView = [UITableView new];
self.tableView.translatesAutoresizingMaskIntoConstraints = NO;
self.tableView.backgroundColor = [UIColor darkGrayColor];
[self.view addSubview:self.tableView];
NSDictionary *views = @{@"topLayoutGuide": self.topLayoutGuide, @"tableView": self.tableView};
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[tableView]-|" options:0 metrics:nil views:views]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[topLayoutGuide]-20-[tableView]-20-|" options:0 metrics:nil views:views]];
}
@end