IOS about TextField Some of the possible

Source: Internet
Author: User

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

  1. Agents that need to implement TextField
  2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.