UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[self.view addSubview:button];
[button setTranslatesAutoresizingMaskIntoConstraints: NO];
// 得到当前视图的最低基准限制,这个是对于Auto Layout constraint来说的。
id bottomGuide = self.bottomLayoutGuide;
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings (button, bottomGuide);
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat: @"V:[button]-20-[bottomGuide]"
options: 0
metrics: nil
views: viewsDictionary]];
[self.view layoutSubviews];
同理可以得到topLayoutGuide,这个是视图最高基准限制
时间: 2024-10-15 00:19:54