2015-08-17 9 views
5

Sto lavorando su tastiera personalizzata per iphone 6 e 6Plus. Ho sviluppato la logica per il tasto Maiusc attivo - inattivo o 123 e tasto abc. ma voglio anche mostrare un simbolo personalizzato come mostrato con la tastiera Apple. per favore controlla l'immagineTastiera personalizzata IOS. Come impostare caratteri speciali nella tastiera personalizzata

enter image description here

attualmente sono in grado di cambiare maiuscolo a minuscolo e 123 a abc, ma come posso impostare questo carattere speciale. NOTA: - Ho cercato una demo molto su github ma non sono in grado di vedere caratteri speciali in nessuna tastiera personalizzata.

Ecco la mia logica per maiuscolo e ABC-123 Button.

-(void)UpparCase:(UIButton*)sender // To make caps or small letter 
{ 

sender.selected=!sender.selected; 
if(sender.selected) 
{ 
    if(isPortrait) 
    { 

    [self.ObjKeyLayout.btnCapKey setBackgroundImage:[UIImage imageNamed:@"upparActive.png"] forState:UIControlStateNormal]; 
    } 
    else 
    { 
     [self.ObjKeyLayout.btnCapKey setBackgroundImage:[UIImage imageNamed:@"Uppar_selctd_land.png"] forState:UIControlStateNormal]; 

    } 

    for(UIButton *key in self.ObjKeyLayout.ArryCharKey) 
    { 


     NSString *uppercaseString = [[key currentTitle] uppercaseString]; 

     [key setTitle:uppercaseString forState:UIControlStateNormal]; 

     [key addTarget:self action:@selector(pressKey:) forControlEvents:UIControlEventTouchUpInside]; 

    } 
    } 
    else 
    { 

    if(isPortrait) 
    { 

    [self.ObjKeyLayout.btnCapKey setBackgroundImage:[UIImage imageNamed:@"UpperCase.png"] forState:UIControlStateNormal]; 
    } 
    else 
    { 
     [self.ObjKeyLayout.btnCapKey setBackgroundImage:[UIImage imageNamed:@"Uppar_land.png"] forState:UIControlStateNormal]; 

    } 
    for(UIButton *key in self.ObjKeyLayout.ArryCharKey) 
    { 


     NSString *uppercaseString = [[key currentTitle] lowercaseString]; 

     [key setTitle:uppercaseString forState:UIControlStateNormal]; 

     [key addTarget:self action:@selector(pressKey:) forControlEvents:UIControlEventTouchUpInside]; 

     } 

    } 
} 

- (IBAction)action123:(UIButton*)sender // To set 123 and ABC 
{ 


sender.selected=!sender.selected; 

if(sender.selected) 
{ 

    [self.ObjKeyLayout.btn123Key setTitle:@"ABC" forState:UIControlStateNormal]; 
      int i=0; 

    for(UIButton *key in self.ObjKeyLayout.ArryCharKey) 
    { 

     [key setTitleColor:[UIColor clearColor] forState:UIControlStateNormal]; 
     NSLog(@"\n\n123isSelected\nI-%i\tArrayCharKey.Count:-%i",i,(int)self.ObjKeyLayout.ArryCharKey.count); 
     if(isPortrait) 
     { 
      NSLog(@"\n\n123isSelected\nI-%i\tArrayCharKey.Count:-%i\nArraySpecialImageKey.Count-%i\n",i,(int)self.ObjKeyLayout.ArryCharKey.count,(int)arrspecialImageKey.count); 
      [key setBackgroundImage:[UIImage imageNamed:[arrspecialImageKey objectAtIndex:i]] forState:UIControlStateNormal]; 




     } 
     else{ 

      [key setBackgroundImage:[UIImage imageNamed:[arrSpecialIpad objectAtIndex:i]] forState:UIControlStateNormal]; 

     } 

     [key setTitle:[NumKey objectAtIndex:i] forState:UIControlStateNormal]; 

     [key addTarget:self action:@selector(pressKey:) forControlEvents:UIControlEventTouchUpInside]; 
     i++; 
    } 
    } 
    else 
    { 
    [self.ObjKeyLayout.btn123Key setTitle:@"123" forState:UIControlStateNormal]; 
    int i=0; 
    for(UIButton *key in self.ObjKeyLayout.ArryCharKey) 
    { 


     [key setTitleColor:[UIColor clearColor] forState:UIControlStateNormal]; 


     if(isPortrait) 
     { 
      [key setBackgroundImage:[UIImage imageNamed:[arrKeyImages objectAtIndex:i]] forState:UIControlStateNormal]; 
     } 
     else 
     { 


      [key setBackgroundImage:[UIImage imageNamed:[keyIpad objectAtIndex:i]] forState:UIControlStateNormal]; 
     } 
     ; 

     NSString *uppercaseString = [arrAlphabet objectAtIndex:i]; 

     [key setTitle:uppercaseString forState:UIControlStateNormal]; 

     [key addTarget:self action:@selector(pressKey:) forControlEvents:UIControlEventTouchUpInside]; 
     i++; 
     // is123selected=NO; 
     } 
    } 

} 

risposta

1

ho impostato il mio problema con questo modo perché ho impostato le immagini delle chiavi anche .

@interface KeyboardViewController() 
{ 
    BOOL ABCselect; 
BOOL select123; 
BOOL keypng; 
BOOL checkactiveshift; 
} 

    -(void)UpparCase:(UIButton*)sender 
{ 

if (ABCselect==YES) { 
    if (isPortrait) { 


        [self.ObjKeyLayout.btnCapKey setBackgroundImage:[UIImage imageNamed:@"key.png"] forState:UIControlStateNormal]; 
        [self.ObjKeyLayout.btnCapKey setTitle:@"" forState:UIControlStateNormal]; 
       } 
       else 
       { 
        [self.ObjKeyLayout.btnCapKey setBackgroundImage:[UIImage imageNamed:@"special_land_key.png"] forState:UIControlStateNormal]; 
        [self.ObjKeyLayout.btnCapKey setTitle:@"" forState:UIControlStateNormal]; 
       } 
    int i=0; 
    // int j=0; 

    for(UIButton *key in self.ObjKeyLayout.ArryCharKey) 
    { 

     [key setTitleColor:[UIColor clearColor] forState:UIControlStateNormal]; 
     NSLog(@"\n\n123isSelected\nI-%i\tArrayCharKey.Count:-%i",i,(int)self.ObjKeyLayout.ArryCharKey.count); 
     if(isPortrait) 
     { 
      NSLog(@"\n\n123isSelected\nI-%i\tArrayCharKey.Count:-%i\nArraySpecialImageKey.Count-%i\n",i,(int)self.ObjKeyLayout.ArryCharKey.count,(int)arrspecialImageKey.count); 
      [key setBackgroundImage:[UIImage imageNamed:[arrspecialImageKey objectAtIndex:i]] forState:UIControlStateNormal]; 

      } 
     else{ 

      [key setBackgroundImage:[UIImage imageNamed:[arrSpecialIpad objectAtIndex:i]] forState:UIControlStateNormal]; 

     } 

     [key setTitle:[NumKey objectAtIndex:i] forState:UIControlStateNormal]; 

     [key addTarget:self action:@selector(pressKey:) forControlEvents:UIControlEventTouchUpInside]; 
     i++; 
     } 

    //select123=NO; 
    keypng=YES; 
    ABCselect=NO; 
    } 

    else if (select123==YES) 
    { 

    if(isPortrait) 
    { 

     [self.ObjKeyLayout.btnCapKey setBackgroundImage:[UIImage imageNamed:@"Caps.png"] forState:UIControlStateNormal]; 
     [self.ObjKeyLayout.btnCapKey setTitle:@"" forState:UIControlStateNormal]; 

    } 
    else 
    { 
     [self.ObjKeyLayout.btnCapKey setBackgroundImage:[UIImage imageNamed:@"Uppar_land.png"] forState:UIControlStateNormal]; 
     [self.ObjKeyLayout.btnCapKey setTitle:@"" forState:UIControlStateNormal]; 


    } 
    for(UIButton *key in self.ObjKeyLayout.ArryCharKey) 
    { 


     NSString *uppercaseString = [[key currentTitle] lowercaseString]; 

     [key setTitle:uppercaseString forState:UIControlStateNormal]; 

     [key addTarget:self action:@selector(pressKey:) forControlEvents:UIControlEventTouchUpInside]; 

    } 
    select123=NO; 
    keypng=NO; 
    checkactiveshift=YES; 

} 
else if (keypng==YES) 
{ 
    [self.ObjKeyLayout.btnCapKey setTitle:@"123" forState:UIControlStateNormal]; 
      //[self.ObjKeyLayout.btnCapKey setTitle:@"" forState:UIControlStateNormal]; 
      [self.ObjKeyLayout.btnCapKey setBackgroundImage:[UIImage imageNamed:@"123.png"] forState:UIControlStateNormal]; 

    [self.ObjKeyLayout.btn123Key setTitle:@"ABC" forState:UIControlStateNormal]; 


      int i=0; 
      for(UIButton *key in self.ObjKeyLayout.ArryCharKey) 
      { 
       [key setTitleColor:[UIColor clearColor] forState:UIControlStateNormal]; 


       if(isPortrait) 
       { 
        [key setBackgroundImage:[UIImage imageNamed:[specialkey2 objectAtIndex:i]] forState:UIControlStateNormal]; 
       } 
       else 
       { 


        [key setBackgroundImage:[UIImage imageNamed:[specialkey2Ipad objectAtIndex:i]] forState:UIControlStateNormal]; 
       } 
       ; 
       [key setTitle:[spec2title objectAtIndex:i] forState:UIControlStateNormal]; 

       [key addTarget:self action:@selector(pressKey:) forControlEvents:UIControlEventTouchUpInside]; 
       i++; 
       // [self action123:(UIButton*)sender]; 
       // [self addGesturToKeyBoard]; 

       //isshiftselected=NO; 
       keypng=NO; 
       ABCselect=YES; 
       // [self action123:(UIButton*)sender]; 
      } 
    } 


    else if(!self.ObjKeyLayout.btnCapKey.isSelected){ 


    sender.selected=!sender.selected; 
    if(sender.selected) 
    { 
     shiftactive=YES; 

     if(isPortrait) 
     { 

      [self.ObjKeyLayout.btnCapKey setBackgroundImage:[UIImage imageNamed:@"upparActive.png"] forState:UIControlStateNormal]; 
     } 
     else 
     { 
      [self.ObjKeyLayout.btnCapKey setBackgroundImage:[UIImage imageNamed:@"Uppar_selctd_land.png"] forState:UIControlStateNormal]; 

     } 

     for(UIButton *key in self.ObjKeyLayout.ArryCharKey) 
     { 


      NSString *uppercaseString = [[key currentTitle] uppercaseString]; 

      [key setTitle:uppercaseString forState:UIControlStateNormal]; 

      [key addTarget:self action:@selector(pressKey:) forControlEvents:UIControlEventTouchUpInside]; 


     } 
      // [sender1 setSelected: NO]; 
      // shift=YES; 
     [sender setSelected: YES]; 
    } 

     else 
     { 

     if(isPortrait) 
     { 

      [self.ObjKeyLayout.btnCapKey setBackgroundImage:[UIImage imageNamed:@"Caps.png"] forState:UIControlStateNormal]; 
     } 
     else 
     { 
      [self.ObjKeyLayout.btnCapKey setBackgroundImage:[UIImage imageNamed:@"Uppar_land.png"] forState:UIControlStateNormal]; 

     } 
     for(UIButton *key in self.ObjKeyLayout.ArryCharKey) 
     { 


      NSString *uppercaseString = [[key currentTitle] lowercaseString]; 

      [key setTitle:uppercaseString forState:UIControlStateNormal]; 

      [key addTarget:self action:@selector(pressKey:) forControlEvents:UIControlEventTouchUpInside]; 

     } 
      // [sender1 setSelected: YES]; 

    } 

    } 
    else if (self.ObjKeyLayout.btnCapKey.isSelected) 
    { 
    if(isPortrait) 
    { 

     [self.ObjKeyLayout.btnCapKey setBackgroundImage:[UIImage imageNamed:@"Caps.png"] forState:UIControlStateNormal]; 
    } 
    else 
    { 
     [self.ObjKeyLayout.btnCapKey setBackgroundImage:[UIImage imageNamed:@"Uppar_land.png"] forState:UIControlStateNormal]; 

    } 
    for(UIButton *key in self.ObjKeyLayout.ArryCharKey) 
    { 


     NSString *uppercaseString = [[key currentTitle] lowercaseString]; 

     [key setTitle:uppercaseString forState:UIControlStateNormal]; 

     [key addTarget:self action:@selector(pressKey:) forControlEvents:UIControlEventTouchUpInside]; 

     } 
     // [sender1 setSelected: YES]; 
     self.ObjKeyLayout.btnCapKey.selected = !self.ObjKeyLayout.btnCapKey.isSelected; 


     } 
    } 

    - (IBAction)action123:(UIButton*)sender 
    { 


    // dummy=YES; 
    sender.selected=!sender.selected; 
    if(sender.selected) 
    { 
    // is123selected=YES; 
    //[self dummy]; 

    [self.ObjKeyLayout.btn123Key setTitle:@"ABC" forState:UIControlStateNormal]; 
    //[self.ObjKeyLayout.btnCapKey setBackgroundImage:[UIImage imageNamed:@"key.png"] forState:UIControlStateNormal]; 
    ABCselect=YES; 
    [self UpparCase:(UIButton*)sender]; 

    int i=0; 
    // int j=0; 

    for(UIButton *key in self.ObjKeyLayout.ArryCharKey) 
    { 

     [key setTitleColor:[UIColor clearColor] forState:UIControlStateNormal]; 
     NSLog(@"\n\n123isSelected\nI-%i\tArrayCharKey.Count:-%i",i,(int)self.ObjKeyLayout.ArryCharKey.count); 
     if(isPortrait) 
     { 
      NSLog(@"\n\n123isSelected\nI-%i\tArrayCharKey.Count:-%i\nArraySpecialImageKey.Count-%i\n",i,(int)self.ObjKeyLayout.ArryCharKey.count,(int)arrspecialImageKey.count); 
      [key setBackgroundImage:[UIImage imageNamed:[arrspecialImageKey objectAtIndex:i]] forState:UIControlStateNormal]; 




     } 
     else{ 

      [key setBackgroundImage:[UIImage imageNamed:[arrSpecialIpad objectAtIndex:i]] forState:UIControlStateNormal]; 

     } 

     [key setTitle:[NumKey objectAtIndex:i] forState:UIControlStateNormal]; 

     [key addTarget:self action:@selector(pressKey:) forControlEvents:UIControlEventTouchUpInside]; 
     i++; 
    } 
    makeshift=NO; 
} 
else 
{ABCselect=NO; 
    [self.ObjKeyLayout.btn123Key setTitle:@"123" forState:UIControlStateNormal]; 
      select123=YES; 
    [self UpparCase:(UIButton*)sender]; 



    int i=0; 
    for(UIButton *key in self.ObjKeyLayout.ArryCharKey) 
    { 


     [key setTitleColor:[UIColor clearColor] forState:UIControlStateNormal]; 


     if(isPortrait) 
     { 
      [key setBackgroundImage:[UIImage imageNamed:[arrKeyImages objectAtIndex:i]] forState:UIControlStateNormal]; 
     } 
     else 
     { 


      [key setBackgroundImage:[UIImage imageNamed:[keyIpad objectAtIndex:i]] forState:UIControlStateNormal]; 
     } 
     ; 

     NSString *uppercaseString = [arrAlphabet objectAtIndex:i]; 

     [key setTitle:uppercaseString forState:UIControlStateNormal]; 

     [key addTarget:self action:@selector(pressKey:) forControlEvents:UIControlEventTouchUpInside]; 
     i++; 
     //is123selected=NO; 
     } 
    } 
    [self.ObjKeyLayout.btnCapKey setSelected: NO]; 

    } 
+1

sì, buona logica per lettere maiuscole. –

2

si prendono due serie di esso, uno per alphabetical e altro per numerical

NSArray *NumKey; 

NSArray *arrAlphabet; 

Ora in NumKey:

NumKey=[[NSArray alloc]initWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"0", @"-", @"/", @":", @";", @"(", @")", @"$", @"&", @"@", @"\"", @".", @",", @"?", @"!",@"'",@"^", nil]; 

e arrAlphabet:

arrAlphabet = [[NSArray alloc]initWithObjects:@"Q", @"W", @"E", @"R", @"T", @"Y", @"U", @"I", @"O", @"P", @"A", @"S", @"D", @"F", @"G", @"H", @"J", @"K", @"L", @"Z", @"X", @"C", @"V", @"B",@"N",@"M", nil]; 

IBOutlet in keyBoard il 123 o ABC.

Aggiunta dell'evento come programmato come di seguito.

[self.keybard.btnNumeric addTarget:self action:@selector(action123:) forControlEvents:UIControlEventTouchUpInside]; 

Metodo per cambiare 123-ABC o ABC per 123

- (IBAction)action123:(UIButton*)sender 
{ 

    if([self.keybard.btnNumeric.titleLabel.text isEqualToString:@"123"]) 
    { 
     [self.keybard.btnCapital setTitle:@"#+=" forState:UIControlStateNormal]; 

     [self.keybard.btnNumeric setTitle:@"ABC" forState:UIControlStateNormal]; 
     int i=0; 
     for(UIButton *key in self.keybard.keyArray) 
     { 
      key.layer.cornerRadius = 6.0; 

      [key setTitle:[NumKey objectAtIndex:i] forState:UIControlStateNormal]; 

      [key addTarget:self action:@selector(pressKey:) forControlEvents:UIControlEventTouchUpInside]; 
      i++; 
     } 
    } 
    else 
    { 
     [self.keybard.btnCapital setTitle:@"⬆️" forState:UIControlStateNormal]; 

     [self.keybard.btnNumeric setTitle:@"123" forState:UIControlStateNormal]; 

     int i=0; 
     for(UIButton *key in self.keybard.keyArray) 
     { 

      strFirstCap = @"0"; 

      NSString *uppercaseString = [arrAlphabet objectAtIndex:i]; 

      [key setTitle:[uppercaseString lowercaseString] forState:UIControlStateNormal]; 

      [key addTarget:self action:@selector(pressKey:) forControlEvents:UIControlEventTouchUpInside]; 
      i++; 
     } 

    } 

} 

uscita:

enter image description here

+0

grazie per il replay ma l'ho già impostato. Voglio sapere del personaggio speciale. come quando si fa clic su 123 il tasto con il carattere speciale mostrato al posto del tasto maiuscole e quando si fa clic su di esso carattere speciale come $, euro o sterlina ecc. carico e 123 impostato al posto del carattere speciale. e quando fai clic su ABC, viene visualizzato nuovamente il tasto maiuscole. per favore controlla l'immagine –

+0

cosa succede quando si fa clic sul pulsante dei caratteri speciali? –

+0

stesso login crea una matrice di simboli. –