【问题标题】:How to fix iPhone screen width using 4 inch storyboard using auto layout?如何使用自动布局使用 4 英寸故事板修复 iPhone 屏幕宽度?
【发布时间】:2015-08-31 08:41:15
【问题描述】:

我是自动布局的新手。我正在使用 iPhone 4 英寸故事板。在视图容器中,我有 4 个按钮。它在 iPhone 5 中运行良好,但在 iPhone 6 和 6+ 中运行时,右侧有一些空间。视图大小是使用以下代码固定的,但不是 4 个按钮。

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    CGRect bounds = self.view.bounds;
    self.contentView.frame = bounds;
}                                     

【问题讨论】:

    标签: storyboard autolayout width iphone-5


    【解决方案1】:
    - (void) viewDidLayoutSubviews {
        self.view.translatesAutoresizingMaskIntoConstraints = NO;
        NSDictionary *bindings = NSDictionaryOfVariableBindings(self.view);
        NSString *formatTemplate = @"%@:|[self.view]|";
        for (NSString * axis in @[@"H",@"V"]) {
            NSString * format = [NSString stringWithFormat:formatTemplate,axis];
            NSArray * constraints = [NSLayoutConstraint constraintsWithVisualFormat:format options:0 metrics:nil views:bindings];
            [self.view.superview addConstraints:constraints];
        }
    
    }
    

    I getting reference from here.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-30
      • 1970-01-01
      • 2017-12-13
      • 2014-11-15
      相关资源
      最近更新 更多