0

For an app that has many UI elements, such as the piano keyboard, adding constraints to it using Interface Builder may be complicated. Adding one by one? On no, I can't do that. So is there a better way to add so many constraints? Programmatically?

Papillon
  • 317
  • 2
  • 10
  • why can't do adding them one by one actually...? that part is not really clear to me. – holex Dec 16 '15 at 15:24
  • what became of this? – Adrian Dec 16 '15 at 19:30
  • @holex Take the piano keyboard as an example, it has 88 keys, and every dimension needs at least 2 constraints. So 88 keys may need hundreds of constraints. Thats a big challenge to Interface Builder. – Papillon Dec 16 '15 at 22:55
  • @AdrianB E.g., a piano keyboard that has 88 keys – Papillon Dec 17 '15 at 00:06
  • This post is kind of old and short on specifics, but the author did include some pseudo code to give you an idea of what he/she did. http://www.deluge.co/?q=content/making-software-piano-keyboard-iphone-and-ipad – Adrian Dec 17 '15 at 03:34
  • 1
    @Papillon, I disagree, it not a big challenge to IB, and you could have set up the constraints in an hour time (at most!) for a piano keyboard with 88 keys, so that is why I don't get your question, because you spend more time looking for alternative answers than doing the obvious. – holex Dec 17 '15 at 09:08

1 Answers1

0

Yes, there are many examples out there of adding autolayout constraints programmatically. See:

Adding Constraints Programmatically on iOS

or

Swift | Adding constraints programmatically

for example.

Community
  • 1
  • 1
joelg
  • 1,094
  • 9
  • 19
  • For complex views like a piano keyboard, I personally prefer this approach. Theoretically, I can loop over each view and add constraints programatically (or use visual format language). But I have not tried. – Papillon Dec 17 '15 at 07:56