How to Add a Login Button to NIB
A NIB file is a user interface file archive created with Interface Builder, a software application for Apple's Mac OS X. Interface Builder is included in the Xcode toolset and is a graphical application for designing user interfaces. Interface builder has an extensive element library that includes buttons, labels, text fields and sliders that you can add to a user interface and connect to the application's code. After building a user interface in Interface Builder, its objects are initialized and saved as an XML file bundle with a .nib extension.
Instructions
-
-
1
Open Xcode by clicking on the Xcode icon located in the Dock or by selecting the application from the Finder. Typically, Xcode is installed in Developer/Applications/Xcode.
-
2
Create a new project in Xcode by selecting the "File" menu and clicking "New Project." Select the "Application" menu item located under "iPhone OS," and choose "View-based Application." Click the "Choose" button to create an application with a single view. Name the project "LoginButton" and click "OK."
-
-
3
Locate the NIB file that was created with the LoginButton project by expanding the "Resources" folder in Xcode or by expanding the "NIB Files" folder. Open LoginButtonViewController.xib by double-clicking the file name in the project explorer. Interface Builder will open and a blank window, or view, will display.
-
4
Ensure that the Library menu is open in Interface Builder by selecting the "Tools" menu and choosing "Library" or by pressing "Command"+"Shift"+"L." The Library window contains a list of objects, or elements, that you can drag onto the View (window) to create the user interface.
-
5
Click on the "Objects" button in the Library window and open the "Inputs & Values" folder. Select a "Round Rect Button," and drag it onto the View window. Click and drag the button to change its location.
-
6
Change the button's title by clicking on the button and double-clicking inside the button to obtain a cursor, or by changing the "Title" field in the button attributes window. Change the button's "Title" to "LOGIN."
-
7
Launch the application in the iPhone Simulator by returning to Xcode and clicking the "Build and Go" button. Save any files if prompted. The iPhone simulator will open and display the View window with the login button by unarchiving the NIB file as part of the application.
-
1
Tips & Warnings
Because NIB files are external to the application's code, localized versions of NIBs may be stored as part of the application bundle.
NIBs are used in other Cocoa touch applications, such as iPod Touch and iPad.
Creating a view-based application, as opposed to a window-based application, adds a configured UIView and a view controller to the application.
As of interface builder 3.0, .nib files have a .xib extension. A .xib file is identical to a .nib file but is stored in a flat file.
Newer versions of Xcode run on Snow Leopard (version 10.6).
Creating complex NIBs with many components and actions can result in memory problems. Include only those objects that are required in a given situation.
References
- Apple Developer: Inspecting the NIB File
- Switch On The Code: An Absolute Beginners Guide to iPhone Development
- iPhone Tutorials: Creating custom UITableViewCell Using Interface Builder
- Apple Developer: Resource Programming Guide
- Programming 4 US: iPhone Application Development: Using the View Based Application Template (Part 1)
Resources
- Photo Credit Jupiterimages/Photos.com/Getty Images