Objective C The default value for the text field is β€œβ€’β€’β€’β€’β€’β€’β€’β€ to β€œ1 ‒‒‒‒‒‒”, β€œ12 ‒‒‒‒‒”, β€œ123 ‒‒‒‒” when the user presses a number

I want to create a text field that has a default value of β€œβ€’β€’β€’β€’β€’β€’β€’β€, when a user clicks a number on UIKeyboardTypeNumberPad, he will add a text field of type β€œ1 ‒‒‒‒‒‒” (for example, press number 1) and β€œ12 ‒‒‒‒‒” (for example, a second press on number 2). Each click on the UIKeyboardTypeNumberPad will be added to the text box, respectively. How can i do this? Thank.

+2
source share
1 answer

I used some tricks to do this.

  • UILable ●●●●●●.
  • UITextField UILable.
  • UITextField storyBoard, UITextField TintColor clearColor ( blink), textColor clearColor ( ) NumberPad.
  • UILable UITextField textAlignment .
  • IBAction, UITextField storyBoard.
  • , .. -

    -(IBAction)textEditingChanged:(UITextField*)sender{
    
            if(sender.text.length==0){
                self.myLable.text=[NSString stringWithFormat:@"●●●●●●●"];
            }
    
            if(sender.text.length==1){
                self.myLable.text=[NSString stringWithFormat:@"%@●●●●●●",sender.text];
            }
    
    
            if(sender.text.length==2){
                self.myLable.text=[NSString stringWithFormat:@"%@●●●●●",sender.text];
            }
    
            if(sender.text.length==3){
                self.myLable.text=[NSString stringWithFormat:@"%@●●●●",sender.text];
            }
    
            if(sender.text.length==4){
                self.myLable.text=[NSString stringWithFormat:@"%@●●●",sender.text];
            }
    
            if(sender.text.length==5){
                self.myLable.text=[NSString stringWithFormat:@"%@●●",sender.text];
            }
    
            if(sender.text.length==6){
                self.myLable.text=[NSString stringWithFormat:@"%@●",sender.text];
            }
            if(sender.text.length==7){
                self.myLable.text=[NSString stringWithFormat:@"%@",sender.text];
                [sender resignFirstResponder];
            }
    
    
        }
    

, , , . .

enter image description here

+1

All Articles