5.1 How to customize key board as per the
requirement
We can customize key pad
as per the user requirements. The key pad type may be Number type, URL ,Phone pad, Email- Address. If the user
wants to enter e-mail id in particular text field, then the developer can set
E-mail address type as key board. Following example shows key board type
settings in iPhone application.
Developer's can set
the key pad via coding as well as attribute window. “setKeyboardType”
is the key to set key board type for particular
text field. The following figure shows the key board type changing via
attribute window,
Also
we can use textField Delegates method to handle the events in textField. We
have to use UITextFieldDelegate in the header section to use the textField
delegates in our application. Also connect the delegate's of TextField in to
file's owner or set the delegate file for particular textField via coding as
follows, [textField setDelegate:self]. Following are the list of textField
delegates available in iPhone application development,
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField; // return NO to disallow editing.
- (void)textFieldDidBeginEditing:(UITextField *)textField; // became
first responder
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField; // return YES to allow editing to stop and to resign first responder status. NO
to disallow the editing session to end
- (void)textFieldDidEndEditing:(UITextField *)textField;
// may be called if
forced even if shouldEndEditing returns NO (e.g. view removed from window) or
endEditing:YES called
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString
*)string; // return NO to not change text
- (BOOL)textFieldShouldClear:(UITextField *)textField; // called when clear button pressed. return NO
to ignore (no notifications)
- (BOOL)textFieldShouldReturn:(UITextField *)textField; // called when 'return' key pressed. return NO
to ignore.
5.2 Implementation of scrollview with example
ScrollView is an object which is used in iPhone application to
show more amount of data in a single view on the basis of scrolling. If the
developer need to present more information in a single view, then he can make
use of scroll view in his application.
Now, we shall see a
view-based application to implement scrollView. As usual, starts with Xcode and
create a view based application. In the header file, add UIScrollView object
and one UIView object. After adding those objects, the header file will be
looking like as follows.
In the implementation section, we have to write coding in ViewDidLoad function. Before that, first we have to connect the outlets in xib files. Set UIView size as 320*650 and come back to implementation section. Now, set the scrollView content size as view size and add the view as sub view for the scroll view via coding in viewDidLoad function. Implementation file coding will be as follows,
Now come again to xib file and you can set properties to scroll
view in it's attribute window.
Add some text fields in the view and build and run the
application, output will be as follows,
4.3 Text view and its delegates
If the developer wants to use multi lined text field, then he
should use Text view for that purpose. Text view can be used to display or get
a certain amount of text data. Text view it self having its own scroll and edit
functionality. We can also customize own text view by changing its attribute
values in attribute window.
Similar to text
field, text view also having it's own delegate functions. To use the text view
delegate , we have to add UITextViewDelegate in the header file. Resigning key
pad coding is not similar to text field, we have to write our own coding for
resigning a key pad in text view delegates.
Now we shall see an
example for text view and its delegate. First create a view based application
in Xcode and come to its header file. Add text view delegate and object in the
header section, the code will be look as follows,
Now
we have to come back in the implementation section. To resign the kay board,
write the codings in the delegate file such as,
-
(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range
replacementText:(NSString *)text
Now
we have to connect the outlet and delegate of text view in the xib file. First
drag and drop UITextView from the object
pane and connect its delegate in the files owner. Build and run the application, finally we
will get the output as follows,
Apart
from this delegate, text view also having delegates such as,
4.4 A simple Login Validation
Now we shall see a
simple Login validation program for iPhone. We can use a view based application
for this program.
In this application,
we are going to validate user name, password and confirm password and email id.
First you have to start with Xcode and create a view based application. Come to
header file and Add textfield delegate and UITextField outlets for user name,
email id and passwords.
The header file will be look as follows,
isValidate is the method
used for validation purpose and “done”
is used to call the validation function. IsValidateEmail is used for email
validation purpose.
Now
we have to write codes in the implementation section. We have define the
functions in implementation file. First we have to define isValidateEmail and
it will be like as follows,
Just
use the above code as standard validation for email-id. After that we have to
define isValidate function. IsValidate function will be as follows,
In
this function, first we have to define two variables namely error and message
for easy access and efficiency. After that we have to check whether all the fields are entered and make sure that
none of the fields are empty, for that purpose we check all the fields are
filled or not. If any field is empty,
alert with error message is pop upped.
Once
the fields are filled, we have to check whether passwords are matched or not,
finally we have to check whether the email id is valid or not. For that
purpose, call isValidEmail function by using [self isValidEmail:tfEmail.text] command.
Finally
define the done action to call the validate function and the done action coding
is look as follows,
Thats
all we have to do in the coding section. Now come to xib file and connect the
outlets and actions. Set password and confirm password text field as secure one by enable the secure
property in TextField attribute window.
In
attribute window for Text Fields, set place holder for each text field in the
xib and finally build and run the application, the output will be as follows,
0 comments:
Post a Comment