Ratata Tata
Ratata Tata

Reputation: 2879

NSLayoutConstraint and dynamic width and height

I have this code:

[parent.view addConstraints:[NSLayoutConstraint
    constraintsWithVisualFormat:@"H:|-(0)-[myView]-(0)-|"
                        options:NSLayoutFormatDirectionLeadingToTrailing
                        metrics:nil
                          views:@{ @"myView":myView }]];

May I understand it wrong, I don't know. I want the myView get all over the parent.view area. But I just got an error:

Unable to simultaneously satisfy constraints.
translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x14d645d0 H:|-(0)-[UIView:0x14d32ce0]   (Names: '|':UILayoutContainerView:0x14dbd6a0 )>",
    "<NSLayoutConstraint:0x14d64600 H:[UIView:0x14d32ce0]-(0)-|   (Names: '|':UILayoutContainerView:0x14dbd6a0 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x16184340 h=-&- v=-&-UIView:0x14d32ce0.midX == UILayoutContainerView:0x14dbd6a0.midX + 140>"
)

I tried @"[myView]-(0)-|", but I got error too.

Upvotes: 0

Views: 491

Answers (1)

dan
dan

Reputation: 9825

You want to set myView.translatesAutoresizingMaskIntoConstraints = NO

Upvotes: 2

Related Questions