Fwd: Under the Bridge: Xcode 6 Custom Interface Builder Previews

13 views
Skip to first unread message

Mathieu Godart

unread,
Sep 19, 2014, 2:11:17 PM9/19/14
to CocoaHeads
Salut tout le monde,

C'est pas nouveau, mais je me trouve ça super cool, alors je vous fait passer le mot. Et en juste deux, ça troue :

We prefix our class with the @IBDesignable keyword to inform Interface Builder that the class’ instances will try to design themselves when added to the storyboard…

Then, prefixing any properties of the class with @IBInspectable, we ensure that Interface Builder can read and write the value of these properties directly in the inspector view…

Bam !

Plus d'info, plus bas.

Mathieu Godart
Co-fondateur et associé

L'Atelier du mobile pense, crée et fait connaître vos applications mobiles

Tél : 06 03 78 74 82
Twitter : @MonsieurDart
31, rue du Caire - 75002 Paris
http://www.atelierdumobile.com



Début du message réexpédié :

Ah, yes. This was the thing that kept us scrabbling on by our fingernails to developing applications in PowerPlant (remember that?) long past when everyone else who could read the writing on the wall had long since jumped ship to Cocoa; not being able to lay out your UI with preview seemed so hopelessly retrograde to us that there was no way we’d work without Constructor unless we had to.

And, well, then Carbon never made it to 64-bit, so we had to for a decade. Funny how these things go.

So although we can’t quite work ourselves up to be quite as celebratory as their effort probably deserves, it does deserve celebration that, FINALLY, our workflow can now include

BUILDING CUSTOM UI ELEMENTS WITH IBDESIGNABLE [AND IBINSPECTABLE]

These two new keywords have been added to Xcode 6 to preview our custom views directly through Interface Builder. That’s right: this is a dramatic improvement in terms of re-usability, sharing, and, in a way, testing.

We prefix our class with the @IBDesignable keyword to inform Interface Builder that the class’ instances will try to design themselves when added to the storyboard…

Then, prefixing any properties of the class with @IBInspectable, we ensure that Interface Builder can read and write the value of these properties directly in the inspector view…

The previous code will end up returning new fields in Interface Builder to setup that property … and in the ViewController in the storyboard we get a preview of the view like for any other UIKit component:

That’s pretty much it really, but read the whole thing for a good walkthrough!

h/t: ManiacDev!



via Under The Bridge » Blog http://ift.tt/1rj8XDo

Reply all
Reply to author
Forward
0 new messages