Skip to content

Auto layout constraints with Visual format language not working properly. #2167

Open

Description

This code works perfectly fine on Xcode simulator but not on WINOBJC. I have been using 10.0.0.14393 windows 10 sdk, visual studio 2015,February 1st 2017 release of WINOBJC

   [scrollView addSubview:label1];
    [scrollView addSubview:button1];
    [scrollView addSubview:button2];
    [scrollView addSubview:button3];
    [scrollView addSubview:button4];
    [scrollView addSubview:button5];
    [scrollView addSubview:button6];
    [scrollView addSubview:button7];
    [scrollView addSubview:button8];
    [container addSubview:scrollView];
    [[self view] addSubview:container];
    [[self view] addSubview:_delegateOutputTextView];


    // constraints
   // All the views have their translatesAutoresizingMaskIntoConstraints = false;
    NSArray *hScrollViewLayoutConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0.0-[scrollView]-0.0-|" options:0 metrics:nil views:viewsDictionary];
    NSArray *vScrollViewLayoutConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[scrollView]-0-|" options:0 metrics:nil views:viewsDictionary];
    [container addConstraints:hScrollViewLayoutConstraints];
    [container addConstraints:vScrollViewLayoutConstraints];
    
    
    NSArray *hContainerLayoutConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0.0-[container]-0.0-|" options:0 metrics:nil views:viewsDictionary];
    NSArray *hTextViewLayoutConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[_delegateOutputTextView]-0-|" options:0 metrics:nil views:viewsDictionary];
    
    NSArray *vContainerLayoutConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[container]-0-[_delegateOutputTextView]" options:0 metrics:nil views:viewsDictionary];
    NSArray *vTextViewLayoutConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-<=500-[_delegateOutputTextView(150)]-0-|" options:0 metrics:nil views:viewsDictionary];
    
    [[self view] addConstraints:hContainerLayoutConstraints];
    [[self view] addConstraints:hTextViewLayoutConstraints];
    [[self view] addConstraints:vContainerLayoutConstraints];
    [[self view] addConstraints:vTextViewLayoutConstraints];


    NSArray *vScrollViewOtherLayoutConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-40-[label1]-20-[button1]-20-[button2]-20-[button3]-20-[button4]-20-[button5]-20-[button6]-20-[button7]-20-[button8]-20-|" options:0 metrics:nil views:viewsDictionary];
    [scrollView addConstraints:vScrollViewOtherLayoutConstraints];

NSLayoutConstraint *hlabel1LayoutConstraints = [NSLayoutConstraint constraintWithItem:label1
    attribute:NSLayoutAttributeCenterX
    relatedBy:NSLayoutRelationEqual
    toItem:label1.superview
    attribute:NSLayoutAttributeCenterX
    multiplier:1.f constant:0.f];
[scrollView addConstraint:hlabel1LayoutConstraints];


NSLayoutConstraint *hbutton1LayoutConstraints = [NSLayoutConstraint constraintWithItem:button1
    attribute:NSLayoutAttributeCenterX
    relatedBy:NSLayoutRelationEqual
    toItem:button1.superview
    attribute:NSLayoutAttributeCenterX
    multiplier:1.f constant:0.f];

NSLayoutConstraint *button1WidthConstraints = [NSLayoutConstraint constraintWithItem:button1
    attribute:NSLayoutAttributeWidth
    relatedBy:NSLayoutRelationEqual
    toItem:nil
    attribute:NSLayoutAttributeNotAnAttribute
    multiplier:1.f constant:250.0f];

[scrollView addConstraint:button1WidthConstraints];
[scrollView addConstraint:hbutton1LayoutConstraints];


NSLayoutConstraint *hbutton2LayoutConstraints = [NSLayoutConstraint constraintWithItem:button2
    attribute:NSLayoutAttributeCenterX
    relatedBy:NSLayoutRelationEqual
    toItem:button2.superview
    attribute:NSLayoutAttributeCenterX
    multiplier:1.f constant:0.f];

NSLayoutConstraint *button2WidthConstraints = [NSLayoutConstraint constraintWithItem:button2
    attribute:NSLayoutAttributeWidth
    relatedBy:NSLayoutRelationEqual
    toItem:nil
    attribute:NSLayoutAttributeNotAnAttribute
    multiplier:1.f constant:250.0f];

[scrollView addConstraint:button2WidthConstraints];
[scrollView addConstraint:hbutton2LayoutConstraints];



NSLayoutConstraint *hbutton3LayoutConstraints = [NSLayoutConstraint constraintWithItem:button3
    attribute:NSLayoutAttributeCenterX
    relatedBy:NSLayoutRelationEqual
    toItem:button3.superview
    attribute:NSLayoutAttributeCenterX
    multiplier:1.f constant:0.f];

NSLayoutConstraint *button3WidthConstraints = [NSLayoutConstraint constraintWithItem:button3
    attribute:NSLayoutAttributeWidth
    relatedBy:NSLayoutRelationEqual
    toItem:nil
    attribute:NSLayoutAttributeNotAnAttribute
    multiplier:1.f constant:250.0f];

[scrollView addConstraint:button3WidthConstraints];
[scrollView addConstraint:hbutton3LayoutConstraints];



NSLayoutConstraint *hbutton4LayoutConstraints = [NSLayoutConstraint constraintWithItem:button4
    attribute:NSLayoutAttributeCenterX
    relatedBy:NSLayoutRelationEqual
    toItem:button4.superview
    attribute:NSLayoutAttributeCenterX
    multiplier:1.f constant:0.f];

NSLayoutConstraint *button4WidthConstraints = [NSLayoutConstraint constraintWithItem:button4
    attribute:NSLayoutAttributeWidth
    relatedBy:NSLayoutRelationEqual
    toItem:nil
    attribute:NSLayoutAttributeNotAnAttribute
    multiplier:1.f constant:250.0f];

[scrollView addConstraint:button4WidthConstraints];
[scrollView addConstraint:hbutton4LayoutConstraints];



NSLayoutConstraint *hbutton5LayoutConstraints = [NSLayoutConstraint constraintWithItem:button5
    attribute:NSLayoutAttributeCenterX
    relatedBy:NSLayoutRelationEqual
    toItem:button5.superview
    attribute:NSLayoutAttributeCenterX
    multiplier:1.f constant:0.f];

NSLayoutConstraint *button5WidthConstraints = [NSLayoutConstraint constraintWithItem:button5
    attribute:NSLayoutAttributeWidth
    relatedBy:NSLayoutRelationEqual
    toItem:nil
    attribute:NSLayoutAttributeNotAnAttribute
    multiplier:1.f constant:250.0f];

[scrollView addConstraint:button5WidthConstraints];
[scrollView addConstraint:hbutton5LayoutConstraints];



NSLayoutConstraint *hbutton6LayoutConstraints = [NSLayoutConstraint constraintWithItem:button6
    attribute:NSLayoutAttributeCenterX
    relatedBy:NSLayoutRelationEqual
    toItem:button6.superview
    attribute:NSLayoutAttributeCenterX
    multiplier:1.f constant:0.f];

NSLayoutConstraint *button6WidthConstraints = [NSLayoutConstraint constraintWithItem:button6
    attribute:NSLayoutAttributeWidth
    relatedBy:NSLayoutRelationEqual
    toItem:nil
    attribute:NSLayoutAttributeNotAnAttribute
    multiplier:1.f constant:250.0f];

[scrollView addConstraint:button6WidthConstraints];
[scrollView addConstraint:hbutton6LayoutConstraints];



NSLayoutConstraint *hbutton7LayoutConstraints = [NSLayoutConstraint constraintWithItem:button7
    attribute:NSLayoutAttributeCenterX
    relatedBy:NSLayoutRelationEqual
    toItem:button7.superview
    attribute:NSLayoutAttributeCenterX
    multiplier:1.f constant:0.f];

NSLayoutConstraint *button7WidthConstraints = [NSLayoutConstraint constraintWithItem:button7
    attribute:NSLayoutAttributeWidth
    relatedBy:NSLayoutRelationEqual
    toItem:nil
    attribute:NSLayoutAttributeNotAnAttribute
    multiplier:1.f constant:250.0f];

[scrollView addConstraint:button7WidthConstraints];
[scrollView addConstraint:hbutton7LayoutConstraints];



NSLayoutConstraint *hbutton8LayoutConstraints = [NSLayoutConstraint constraintWithItem:button8
    attribute:NSLayoutAttributeCenterX
    relatedBy:NSLayoutRelationEqual
    toItem:button8.superview
    attribute:NSLayoutAttributeCenterX
    multiplier:1.f constant:0.f];

NSLayoutConstraint *button8WidthConstraints = [NSLayoutConstraint constraintWithItem:button8
    attribute:NSLayoutAttributeWidth
    relatedBy:NSLayoutRelationEqual
    toItem:nil
    attribute:NSLayoutAttributeNotAnAttribute
    multiplier:1.f constant:250.0f];

[scrollView addConstraint:button8WidthConstraints];
[scrollView addConstraint:hbutton8LayoutConstraints];```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions