Frederick C. Lee
Frederick C. Lee

Reputation: 9513

Is there a way to get the 'Visual-Format Language' of AutoLayout XIB?

I'm slamming into brick walls. Is it possible to get the Visual-Format Language generated from an AutoLayout XIB?

I wish to emulate the XIB equivalent in code.

Upvotes: 1

Views: 1443

Answers (1)

John Sauer
John Sauer

Reputation: 4421

When you NSLog constraints, the log displays them in the visual format language.

NSLog(@"%@", self.view.constraints) ;

I created a UIButton in Interface Builder and dragged it to the upper-right corner of a view, , and here's the NSLog:

"<NSLayoutConstraint:0x75b19f0 H:[UIRoundedRectButton:0x75ae6a0]-(NSSpace(20))-|   (Names: '|':UIView:0x75ae560 )>",
"<NSLayoutConstraint:0x75b1a50 V:|-(NSSpace(20))-[UIRoundedRectButton:0x75ae6a0]   (Names: '|':UIView:0x75ae560 )>"

They're the same as creating constraints with visual format language:

H:[button]-20-|
V:|-20-[button]

If you're familiar enough with the visual format language, you should be able to express most constraints you can think of in the language, without needing to create them in Interface Builder and reverse-engineer them. Let me know if there's a constraint that you're unable to build in code.

Upvotes: 6

Related Questions