In the development of mobile iOS, there will often be input forms like the following
These seem to have no input effect, in fact, are TextField, of course, can also be implemented with other controls, but in the case of the same partition, with a unified control to achieve easy to simplify the code;
1, the front two kinds is the click does not have the effect, uses textfield.enable = No, realizes, then will appear the effect with the label same display effect, and many placeholder;
2, two of the rectangular box is not with the editing function, but support the Click event function, its implementation can be achieved by the way:
Realize the Textfeild
[TextField addtarget:self Action: @selector (textfieldstataediting:) forcontrolevents:uicontroleventeditingdidbegin ];
According to the tag to determine which textfield you need, and then do the corresponding processing
-(void) textfieldstataediting: (uitextfield*) textfield{
if (Textfield.tag = = 2) {
[TextField Resignfirstresponder];
[Self showtimeselectview];//here for click events
Return
}
if (Textfield.tag = = 5) {
[TextField Resignfirstresponder];
[Self showaddressselectview]; Click here for Event
Return
}
}
3, then a format like a phone number with a space or a horizontal line
- Agents that need to implement TextField
- Implementing Proxy methods
-(void) Textfieldedingchange: (uitextfield*) textfield{
if (Textfield.tag = = 4) {
nsstring* tempstring = [TextField getstringfilterspecialcharacter:@ ""];
if (tempstring.length = = 11) {
[TextField Resignfirstresponder];
}
}
}
-(BOOL) TextField: (Uitextfield *) TextField Shouldchangecharactersinrange: (nsrange) range replacementstring: ( NSString *) string{
if (Textfield.tag = = 4) {
return [TextField Setphonenumberstyleshouldchangecharactersinrange:range replacementstring:string];
}
return YES;
}
which
/**
Set the display format for phone numbers (e.g.: 112 1189 9876)
@param range Length
@param a string input character
@return returns whether you can continue typing
*/
-(BOOL) Setphonenumberstyleshouldchangecharactersinrange: (nsrange) Range replacementstring: (NSString *) string{
Nsuinteger proposednewlength = textfield.text.length-range.length + string.length;
String.length>0 to perform the add operation at this time
if (string.length>0) {
Nsmutablestring *str=[nsmutablestring StringWithString:self.text];
while (self.text.length==3| | SELF.TEXT.LENGTH==8) {
if (self.text.length==3) {
[Str insertstring:@ "" atindex:3];
}
else if (self.text.length==8) {
[Str insertstring:@ "" atindex:8];
}
Self.text = [NSString stringwithstring:str];
}
}
String.length=0 The delete operation is now performed
else if (string.length==0) {
Nsmutablestring *str=[nsmutablestring StringWithString:self.text];
while (self.text.length==5| | self.text.length==10) {
if (self.text.length==5) {
[Str deletecharactersinrange:nsmakerange (4, 1)];
}
else if (self.text.length==10) {
[Str deletecharactersinrange:nsmakerange (9, 1)];
}
Self.text = [NSString stringwithstring:str];
}
NSLog (@ "%@", Textfield.text);
}
Limit the input length to 13. (Dividing line is also counted)
if (Self.text.length > 13) {
return no;//Limit length
}
return YES;
}
It is recommended to write to the TextField classification, which is convenient to call at any time, which realizes the format control of the mobile phone number.
IOS about TextField Some of the possible