MOBILE

iPhone Application Development : Basic User Input and Output

1/15/2011 3:39:36 PM
Buttons

One of the most common interactions you’ll have with your users is detecting and reacting to the touch of a button (UIButton). Buttons, as you may recall, are elements of a view that respond to an event that the user triggers in the interface, usually a Touch Up Inside event to indicate that the user’s finger was on a button and then released it. Once an event is detected, it can trigger an action (IBAction) within a corresponding view controller.

Buttons are used for everything from providing preset answers to questions to triggering motions within a game. Although we’ve used only a single Rounded Rect button up to this point, they can take on many different forms through the use of images. Figure 1 shows an example of a fancy button.

Figure 1. Buttons can be simple, fancy (like this one), or set to any arbitrary image.


Text Fields and Views

Another common input mechanism is a text field. Text fields (UITextField) give users space to enter any information they’d like into a single line in the application—these are similar to the form fields in a web form. When users enter data into a field, you can constrain their input to numbers or text by using different iPhone keyboards, something we do later this hour. Text fields, like buttons, can respond to events but frequently are implemented as passive interface elements, meaning that their contents (provided through the text property) can be read at any time by the view controller.

Similar to the text field is the text view (UITextView). The difference is a text view can present a scrollable and editable block of text for the user to either read or modify. These should be used in cases where more than a few words of input are required. Figure 7.2 shows examples of a text field and text view.

Figure 7.2. Text fields and text views provide a means for entering text using the iPhone’s virtual keyboard.


Labels

The final interface feature that we’re going to be using here and throughout this book is the label (UILabel). Labels are used to display strings within a view by setting their text property.

The text within a label can be controlled via a wide range of label attributes, such as font and text size, alignment, and color. As you’ll see, labels are useful both for static text in a view and for presenting dynamic output that you generate in your code.

Now that you have basic insight into the input and output tools we’ll be using in this hour, let’s go ahead and get started with our project: a simple substitution-style story generator.

Other  
  •  Mobile Phone Game Programming : A Quick J2ME Primer
  •  Mobile Phone Game Programming : Java As a Mobile Game Platform
  •  Mobile Phone Game Programming : Getting to Know Mobile Platforms
  •  Mobile Application Security : The Apple iPhone - Local Data Storage: Files, Permissions, and Encryption
  •  Mobile Application Security : The Apple iPhone - Permissions and User Controls
  •  iPhone Application Developmen : Using the View-Based Application Template (part 3)
  •  iPhone Application Developmen : Using the View-Based Application Template (part 2) - Preparing the View Controller Outlets and Actions
  •  iPhone Application Developmen : Using the View-Based Application Template (part 1)
  •  Mobile Application Security: Application Format
  •  Mobile Application Security: Security Testing
  •  Mobile Application Security: The Apple iPhone - Development
  •  Building Android Apps : Installing KiloGap in the Emulator
  •  Building Android Apps : Build KiloGap
  •  Building Android Apps: Create an Android Virtual Device
  •  Building Android Apps: Going Native - Setting Up the Environment
  •  Building Android Apps: Introduction to PhoneGap
  •  iPhone Application Development : How Xcode and Interface Builder Implement MVC
  •  iPhone Application Development : Understanding the Model-View-Controller Paradigm
  •  Building Android Apps: Going Offline - Debugging
  •  Building Android Apps: Creating a Dynamic Manifest File
  •  
    Top 10
    -  Migrating from Legacy SharePoint to SharePoint Server 2010 : Planning for an Upgrade to SharePoint 2010
    -  Understanding Snapshot Isolation
    -  Building and Deploying Applications for Windows Azure : Creating a Demo Project
    -  IIS 7.0 : Striking a Balance Between Security and Performance - How to Measure Overhead
    -  Security Changes in IIS 7.0 : Reducing Attack Surface Area (part 2)
    -  Designing and Implementing Mobility in Exchange Server 2010 : Working with Windows Mobile Pocket PC and Smartphone Editions
    -  Installing and Maintaining Devices in Vista: The Essentials
    -  iPhone 3D Programming : Adding Depth and Realism - Filling the Wireframe with Triangles
    -  Personalizing Windows 7 (part 2) - Choosing Your Desktop Background
    -  Developing an SEO-Friendly Website: Content Delivery and Search Spider Control (part 1)
    Most View
    -  Windows Phone 7 Development : Building a Phone Client to Access a Cloud Service (part 3) - Coding the BoolToVisibilityConvert
    -  Microsoft XNA Game Studio 3.0 : Working with Colors
    -  SQL Server System and Database Administration : System Views
    -  Reporting Services with SQL Azure : Creating the SQL Azure Data Source
    -  Registry ACLs
    -  Exchange Server 2010 : Installing OCS 2007 R2 (part 3) - Configuring Prerequisites & Deploying an OCS 2007 Server
    -  SQL Server 2005 : Transactions and Exceptions
    -  Windows Server 2008 : Configuring and Monitoring Terminal Service Resources
    -  The Language of Apple Platforms : Memory Management
    -  Windows Phone 7 Development : Working with Isolated Directory Storage (part 2)
    -  Programming .NET Security : Symmetric Encryption Explained (part 3)
    -  Executing Work on a Background Thread with Updates
    -  SQL Server 2008 : Performance Tuning - Working with Query Execution Plans
    -  Advanced ASP.NET : Data Caching (part 2) - Caching to Provide Multiple Views
    -  Recovering from a Disaster in an Exchange Server 2010 Environment : Recovering from Database Corruption
    -  SQL Server 2008 : Transact-SQL Programming - Common Table Expressions
    -  iPhone 3D Programming : Adding Depth and Realism - Better Wireframes Using Polygon Offset
    -  Exchange Server 2010 : SIP Protocol
    -  WCF Services : Versioning
    -  Parallel Programming with Microsoft .Net : Pipelines - Variations