lunes, 12 de diciembre de 2011

Introduction to the Interface Builder

The interface builder is a great tool for designing the user interface (user interface) of our application.
From XCode 4, Interface Builder is integrated into XCode and can be used with ".xib" files.
XIB, short for Mac OS X Interface Builder, are XML files that contain the positions, types of elements and controls that contains the view you are creating.


The controls are part of the xib and must be IBOutlet type, so if we want to create a button in our view, we need to create it inside @interface.


  1. @interface xibTestViewController : UIViewController
  2. {
  3.       IBOutlet UIButton *_customButton;
  4. }


In case of events, for example when you press the button (event TouchUpInside:), action must be IBAction. Tapping the button will call an event like this:

  1. //Touch event
  2. -(IBAction) customButtonTouched:(id)sender;

After writing this in the interface, we can go to ".xib" file and drag a button to the view, as we see in the picture





Pressing right button we will see that it will list the events you can call, and also the ability to reference the IBOutlet.
Remember that the IBOutlet will serve to change control properties, such as text, size, among others.


We will see something like this:



If we hold down on the circle at the right of each event, and drag on "File's Owner", we will be able to see all IBOutlet controls that are in the interface, in this case, the buttons.


This is a quick introduction to the interface builder, I will post later more advanced articles on it.

No hay comentarios:

Publicar un comentario