1.UITextField initialization and setup TextField = [[Uitextfield alloc] Initwithframe:cgrectmake (120.0f, 80.0f, 150.0f, 30.0f)]; [TextField Setborderstyle:uitextborderstyleroundedrect]; Frame type//If Uitextfield does not appear, it is most likely not set its borderstyle textfield.placeholder = @ "password"; The default display character textfield.securetextentry = YES;
Password Textfield.autocorrectiontype = Uitextautocorrectiontypeno;
Textfield.autocapitalizationtype = Uitextautocapitalizationtypenone;
Textfield.returnkeytype = Uireturnkeydone; Textfield.clearbuttonmode = uitextfieldviewmodewhileediting;
The edit will appear with a modified x textfield.delegate = self; 2. To implement the delegate method, turn off the keyboard-(BOOL) Textfieldshouldreturn: (Uitextfield *) TextField {[Self.textfield resignfirstresp
Onder];
return YES; } 3.
You can use the following method in Uitextfield to return-(ibaction) Textfielddone: (ID) Sender {[Textfieldname resignfirstresponder]; The rightmost picture of the Did end on exit of the linked TextField control is the following code, Uiimageview *imgv=[[uiimageview alloc] Initwithimage:[uiimage Imagenamed:@ "Right.png"]];
TEXT.RIGHTVIEW=IMGV;
Text.rightviewmode = Uitextfieldviewmodealways;
If you add a picture on the left, replace it with: TEXT.LEFTVIEW=IMGV;
Text.leftviewmode = Uitextfieldviewmodealways;
Uitextfield inherits from Uicontrol, there is a property in this class contentverticalalignment so you want the text inside Uitextfield to be centered vertically so that you can write:
Text.contentverticalalignment = Uicontrolcontentverticalalignmentcenter;
To view a function: Hold down the Command key and double-click to enter the function declaration alt-Click to enter DOC document///////////////////////////////////////////////////////////////
Text box Common method: How to use the program to delete the text box selected text [TextView Delete:nil]; How to restrict a text box to only enter numbers: Create Nsnumberformatter Subclasses, add this method,
Link formatter to a text box. -(BOOL) Ispartialstringvalid: (NSString * *) partialstringptr Proposedselectedrange: (nsrangepointer) ProposedSelR
Angeptr originalstring: (NSString *) origstring Originalselectedrange: (nsrange) Origselrange
ErrorDescription: (NSString * *) error {Nscharacterset *nondigits;
Nsrange Newstuff; NSString *newstuffstring;
Nondigits = [[Nscharacterset decimaldigitcharacterset] invertedset];
Newstuff = Nsmakerange (origselrange.location, proposedselrangeptr->location
-Origselrange.location);
newstuffstring = [*partialstringptr Substringwithrange:newstuff];
if ([Newstuffstring rangeofcharacterfromset:nondigits
Options:nsliteralsearch].location!= nsnotfound) {*error = @ "not a number";
return (NO);
else {*error = nil;
return (YES); }///////////////////////////////////////////////////////////////code char that obtains hexadecimal data from the text box singlenumberstring[3
] = {' A ', ' a ', ' and ' ';
uint32_t singlenumber = 0;
uint32_t i = 0;
Nsmutabledata *data = [Nsmutabledata data];
Get Data from text box const char *BUF = [[_hextosendtextfield text] utf8string]; Convert to hexadecimal for (i = 0; i < strLen (BUF);
i+=2) {if ((i+1) < Len && Isxdigit (buf) && (Isxdigit (buf[i+1))) {singlenumberstring[0] = buf;
SINGLENUMBERSTRING[1] = buf[i+1];
SSCANF (singlenumberstring, "%x", &singlenumber); [Data appendbytes: (void*)
(&tmp) length:1];
} else {break;
}//Output NSLog (@ "%@", data); Click Uitextview Enter text, the cursor starts from the initial point-(void)
Textviewdidchangeselection: (Uitextview *) TextView {Nsrange range;
range.location = 0;
range.length = 0;
Textview.selectedrange = range; ///////////////////////////////////////////////////////////Soft keyboard in the login page to implement the username and password, if the password dot format, the introduction of the current page cursor to stay in the username option, Soft keyboard to eject interface.
The following figure: Pop-up keyboard: [username Becomefirstresponder];
Cancel keyboard: [username Resignfirstresponder];
Password protection: Password.securetextentry=yes; Initialization and setting of 1.UITextField TextField = [[Uitextfield
Alloc] Initwithframe:cgrectmake (120.0f, 80.0f, 150.0f, 30.0f)]; [TextfielD Setborderstyle:uitextborderstyleroundedrect]; Outer frame Type Textfield.placeholder = @ "password"; The default display character textfield.securetextentry = YES;
Password Textfield.autocorrectiontype = Uitextautocorrectiontypeno;
Textfield.autocapitalizationtype = Uitextautocapitalizationtypenone;
Textfield.returnkeytype = Uireturnkeydone; Textfield.clearbuttonmode = uitextfieldviewmodewhileediting;
The edit will appear with a modified x textfield.delegate = self; 2. To implement the delegate method, turn off the keyboard-(BOOL) Textfieldshouldreturn: (Uitextfield *) TextField {[Self.textfield resignfirstresp
Onder];
return YES; } 3.
You can use the following method in Uitextfield to return-(ibaction) Textfielddone: (ID) Sender {[Textfieldname resignfirstresponder]; The Did end on exit////////////////////////////////////////////////////////////////////of the linked TextField control restricts the length of the input text-( BOOL) TextField: (Uitextfield *) TextField Shouldchangecharactersinrange: (nsrange) Range replacementstring: (NSString * ) string {if (range.location >= max_length) return NO;
Return NO to Don't change text return YES;
} if (textField.text.length >= && range.length = 0) return NO;
return YES; -(BOOL) TextField: (Uitextfield *) TextField Shouldchangecharactersinrange: (nsrange) range replacementstring: ( NSString *) String {if ([Textfield.text length] > MAXLENGTH) {textfield.text = [Textfield.text Substringtoinde
X:MAXLENGTH-1];
return NO;
return YES; //////////////////////////////////////////////////////////////////////use Uitextfielddelegate to hide the keyboard on the iphone interface, It is often necessary to hide the keyboard after the user has entered the content.
There are many ways, of course, to use the Uitextfielddelegate protocol to implement the hidden keyboard today. Actually very simple, need three steps: 1. In your controller class, join uitextfielddelegate this protocol, such as: @interface Additemviewcontroller:uiviewcontroller <uitextfielddelegate > 2.
In the implementation of the Controller class using the Uitextfielddelegate protocol, add-(BOOL) Textfieldshouldreturn: Method.
-(BOOL) Textfieldshouldreturn: (Uitextfield *) TextField {[TextField resignfirstresponder];
return YES;
//Set Focus: [Uitextfield Becomefirstresponder]; 3. The TextField control in the Xib fileThe delegate variable points to the Controller class that previously used the Uitextfielddelegate protocol, and the delegate iboutlet variable of the TextField is linked to an instance of the previous controller class.
Or use the code method to specify the delegate variable for the related TextField.
-(void) viewdidload {[Super viewdidload];
Itemnamefield.delegate = self;
Pricefield.delegate = self;
} ---------------------------
1. Create and initialize
Create the Uitextview file and write the following code in the. h file:
#import <UIKit/UIKit.h>
@interface textviewcontroller:uiviewcontroller <UITextViewDelegate>
{
Uitextview *textview;
}
@property (nonatomic, retain) Uitextview *textview;
@end
Initialize the TextView in the. m file and write the code as follows:
| Self.textview = [[[Uitextview alloc] initWithFrame:self.view.frame] autorelease]; Initialize size and automatically release |
| Self.textView.textColor = [Uicolor blackcolor];//set the font color inside the TextView |
| Self.textView.font = [Uifont fontwithname:@ ' Arial ' size:18.0];//set font name and font size |
| Self.textview. delegate = self;//Set its Delegate method |
| Self.textView.backgroundColor = [Uicolor whitecolor];//sets its background color |
| Self.textView.text = @ "Now is the" "the" good developers to come to serve their country.\n\nnow is the Good developers to come to serve their country. ";/ /Set What it displays |
| Self.textView.returnKeyType = uireturnkeydefault;//Return key type |
| Self.textView.keyboardType = uikeyboardtypedefault;//keyboard type |
| self.textView.scrollEnabled = yes;//Whether you can drag |
| Self.textView.autoresizingMask = uiviewautoresizingflexibleheight;//Adaptive height |
| [Self.view addsubview:self.textview];//added to the entire page |
2. Uitextview exit the keyboard in several ways
Because you click Uitextview will appear keyboard, if you exit the keyboard, there are several ways:
(1) If your program has a navigation bar, you can add more than one done button on the navigation bar, used to exit the keyboard, of course, first real uitextviewdelegate.
The code is as follows:
| -(void) textviewdidbeginediting: (Uitextview *) TextView { |
| Uibarbuttonitem *done = [[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemdone target:self Action: @selector (Leaveeditmode)] autorelease]; |
| Self.navigationItem.rightBarButtonItem = done; |
| -(void) textviewdidendediting: (Uitextview *) TextView { |
| Self.navigationItem.rightBarButtonItem = nil; |
| [Self.textview Resignfirstresponder]; |
(2) If you do not use the ENTER key in the TextView, you can use the Enter to exit the keyboard response keys.
The code is as follows:
| #pragma mark-uitextview Delegate Methods |
| -(BOOL) TextView: (Uitextview *) TextView Shouldchangetextinrange: (nsrange) Range Replacementtext: (NSString *) text |
| if ([Text isequaltostring:@ "\ n"]) { |
|
| [TextView Resignfirstresponder]; |
|
This way, whether you're using the ENTER key on your computer's keyboard or using the return button on your pop-up keyboard, you can get out of the keyboard.
(3) and you can also customize the other loaded keyboard to exit, such as a pop-up keyboard above a view to put the quit the keyboard done button.
The code is as follows:
| Uitoolbar * TopView = [[Uitoolbar alloc]initwithframe:cgrectmake (0, 0, 320, 30)]; |
| [TopView Setbarstyle:uibarstyleblack]; |
|
| Uibarbuttonitem * Hellobutton = [[Uibarbuttonitem alloc]initwithtitle:@ "Hello" style:uibarbuttonitemstylebordered Target:self Action:nil]; |
|
| Uibarbuttonitem * Btnspace = [[Uibarbuttonitem alloc]initwithbarbuttonsystemitem:uibarbuttonsystemitemflexiblespace Target:self Action:nil]; |
|
| Uibarbuttonitem * Donebutton = [[Uibarbuttonitem alloc]initwithtitle:@ ' done ' style:uibarbuttonitemstyledone target: Self action: @selector (Dismisskeyboard)]; |
|
| Nsarray * Buttonsarray = [Nsarray arraywithobjects:hellobutton,btnspace,donebutton,nil]; |
|
| [TopView Setitems:buttonsarray]; |
|