Controls Part One: Using Buttons, Sliders, Switches, and Text Fields in Objective-C

Maker Quick Response Code in Objective-C Controls Part One: Using Buttons, Sliders, Switches, and Text Fields

Controls Part One: Using Buttons, Sliders, Switches, and Text Fields
Draw Denso QR Bar Code In Objective-C
Using Barcode maker for iPhone Control to generate, create QR-Code image in iPhone applications.
Barcode Generator In Objective-C
Using Barcode creator for iPhone Control to generate, create barcode image in iPhone applications.
Figure 12-19
Creating Quick Response Code In C#
Using Barcode generation for VS .NET Control to generate, create QR-Code image in Visual Studio .NET applications.
QR Code Printer In Visual Studio .NET
Using Barcode drawer for ASP.NET Control to generate, create Quick Response Code image in ASP.NET applications.
Setting a text field s keyboard type
Generating Quick Response Code In .NET
Using Barcode generation for Visual Studio .NET Control to generate, create QR Code image in VS .NET applications.
Encode Denso QR Bar Code In VB.NET
Using Barcode maker for Visual Studio .NET Control to generate, create QR image in Visual Studio .NET applications.
Figure 12-20
Painting Bar Code In Objective-C
Using Barcode creation for iPhone Control to generate, create barcode image in iPhone applications.
Encoding GTIN - 128 In Objective-C
Using Barcode generator for iPhone Control to generate, create EAN / UCC - 13 image in iPhone applications.
Valid choices for a keyboard s return key
Encode Data Matrix In Objective-C
Using Barcode drawer for iPhone Control to generate, create ECC200 image in iPhone applications.
EAN-13 Encoder In Objective-C
Using Barcode creation for iPhone Control to generate, create UPC - 13 image in iPhone applications.
iOS SDK Programming: A Beginner s Guide
Code 128 Code Set C Creation In Objective-C
Using Barcode generator for iPhone Control to generate, create Code 128B image in iPhone applications.
UPCA Creation In Objective-C
Using Barcode generator for iPhone Control to generate, create UPC Code image in iPhone applications.
Try This
EAN-8 Supplement 2 Add-On Maker In Objective-C
Using Barcode creator for iPhone Control to generate, create European Article Number 8 image in iPhone applications.
Bar Code Creator In None
Using Barcode generation for Font Control to generate, create barcode image in Font applications.
Using UITextField (with a Number Pad)
Print Bar Code In VS .NET
Using Barcode generation for Reporting Service Control to generate, create bar code image in Reporting Service applications.
EAN 128 Encoder In VS .NET
Using Barcode generation for Visual Studio .NET Control to generate, create UCC-128 image in .NET framework applications.
1 Create a new View-based Application named TextField 2 Open TextViewControllerxib in Interface Builder Drag two UITextField controls from the
UCC-128 Creation In Java
Using Barcode generation for Android Control to generate, create UCC - 12 image in Android applications.
Code-128 Recognizer In Java
Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications.
library to the view s canvas and resize the text fields
Barcode Scanner In VB.NET
Using Barcode Control SDK for VS .NET Control to generate, create, read, scan barcode image in VS .NET applications.
Make Data Matrix In C#.NET
Using Barcode drawer for .NET Control to generate, create Data Matrix image in .NET applications.
3 Select the second text field and in its inspector, change its Keyboard to Number Pad 4 Select the first text field and change its Return Key to Done 5 Save your changes 6 Open TextFieldViewController and implement the textFieldDone action (Listings 12-5 and
12-6) Also, add an IBOutlet for the second text field and implement the numberFieldDone method Listing 12-5 TextFieldViewControllerh
#import <UIKit/UIKith> @interface TextFieldViewController : UIViewController { UITextField * numberField; } @property(nonatomic, retain) IBOutlet UITextField * numberField; - (IBAction) textFieldDone: (id) sender; - (IBAction) numberFieldDone: (id) sender; @end
Listing 12-6
TextFieldViewControllerm
#import "TextFieldViewControllerh" @implementation TextFieldViewController @synthesize numberField; - (IBAction) textFieldDone: (id) sender { [sender resignFirstResponder]; } - (IBAction) numberFieldDone: (id) sender { [numberField resignFirstResponder]; } - (void)dealloc { [numberField release]; [super dealloc]; } @end
12:
Controls Part One: Using Buttons, Sliders, Switches, and Text Fields
Figure 12-21
The number pad has no Done key
7 Save and then open TextFieldViewControllerxib Connect the textFieldDone action to the
first text field s Did End on Exit event
8 Save and click Run Notice that when finished editing the first text field, upon clicking
Done, the text pad disappears The number pad, though, has no Done key (Figure 12-21)
9 Reopen TextFieldViewControllerxib and drag a button onto the view s canvas Resize the
button to cover the entire canvas
10 In the Document window, expand the View and ensure the newly added button is behind
the two text fields (Figure 12-22)
11 In the Inspector s Button Attributes pane, change the button s Type to custom and uncheck
any checked drawing check boxes (Figure 12-23)
12 Connect the numberField outlet to the second text field Connect the numberFieldDone
action to the Touch Up Inside event for the button added to the canvas (Figure 12-24)
13 Save and then click Run Click the second text field and the number pad appears Tap
anywhere outside the two text fields to close the number pad Tapping in the first text field causes the number pad to switch to the keyboard (Figure 12-25) Note that in textFieldDone and numberFieldDone we are calling the resignFirstResponder method This is an essential step that actually dismisses the keyboard
(continued)
iOS SDK Programming: A Beginner s Guide
Figure 12-22
Button is under two textfields
Figure 12-23
Changing button s type to Custom
12:
Controls Part One: Using Buttons, Sliders, Switches, and Text Fields
Figure 12-24
Connecting the numberFieldDone action to the button
Figure 12-25
The number pad appears and disappears from the application
iOS SDK Programming: A Beginner s Guide
UITextView
Use a UITextView to capture multiple lines of text in a scrollable, multiline text area It s generally used for entering paragraphs of text rather than a single line There are several properties you can set to customize the control s appearance, including the font, textColor, editable, and textAlignment properties You can also check if it has text using the hasText method Figure 12-26 illustrates several properties you might want to set for a UITextView in Interface Builder For more information on the UITextView, refer to the UITextView Class Reference
Figure 12-26
UITextView properties you might want to set in Interface Builder
12:
Controls Part One: Using Buttons, Sliders, Switches, and Text Fields
UISegmentedControl
A segmented control groups together two or more segments, where each segment acts as an independent button The next task illustrates a segmented control
Try This
Using a UISegmentedControl
1 Create a new View-based Application named Segment 2 Add the images colorizepng and wizardpng from the resources folder to the Resources
folder in Groups & Files
3 Open SegmentViewControllerxib and add a Segmented Control to the view s canvas 4 Change the control so that it has three segments Change the Segment 0 s name to Kids,
the first segment s image to colorizepng, and the second segment s image to wizardpng (Figure 12-27) Change the control s style to Bordered
Figure 12-27
Modifying the segmented control in Interface builder
(continued)
iOS SDK Programming: A Beginner s Guide
5 Save your changes 6 Open SegmentViewController and add an IBAction called handleSegment to
SegmentViewController (Listings 12-7 and 12-8) Listing 12-7 SegmentViewControllerh
#import <UIKit/UIKith> @interface SegmentViewController : UIViewController { } - (IBAction) handleSegment: (id) sender; @end
Listing 12-8
SegmentViewControllerm
#import "SegmentViewControllerh" @implementation SegmentViewController - (IBAction) handleSegment: (id) sender { UISegmentedControl * myseg = (UISegmentedControl *) sender; if(mysegselectedSegmentIndex == 0) { NSLog(@"selected zero index"); } else if(mysegselectedSegmentIndex == 1) { NSLog(@"selected one index"); } else { NSLog(@"selected two index"); } } - (void)dealloc { [super dealloc]; } @end 7 Save and then switch to SegmentViewControllerxib 8 Connect the segment s Value Changed event to the File s Owner handleSegment method 9 Save your changes and click Run Figure 12-28 illustrates the application s appearance,
and Listing 12-9 contains the Debugger Console s logging
12:
Controls Part One: Using Buttons, Sliders, Switches, and Text Fields
Figure 12-28
The application running in iPhone Simulator
Listing 12-9
The Debugger Console s logging for application
2010-09-09 10:47:03535 Segment[19281:207] selected one index 2010-09-09 10:47:19737 Segment[19281:207] selected two index
The Web View
This chapter wraps up its discussion of controls by discussing the web view The UIWebView is the class you use to add a web browser to your application It s based upon the same code foundation as Safari, and so you can use CSS and JavaScript Using the web view can be easy or more difficult, depending upon how much you want your application to interact with the browser In this chapter we keep it simple
Copyright © OnBarcode.com . All rights reserved.