5

I am working on custom keyboard for iphone 6 and 6Plus. I have develop logic for shift key active - inactive or 123 and abc key . but i want to also display custom symbol like apple keyboard shown. please check in image .

enter image description here

currently i am able to change uppercase to lowercase and 123 to abc but how can i set this special character. NOTE:- I searched a lot demo on github but i am not able to see special character in any custom keyboard.

Here is my logic for uppercase and 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;
      }
  }

}
Badal Shah
  • 7,541
  • 2
  • 30
  • 65

2 Answers2

2

You take two array of it, one for alphabetical and other for numerical

NSArray *NumKey;

NSArray *arrAlphabet;

Now in NumKey :

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

and 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 the 123 or ABC.

Adding the event as programmatically as below.

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

Method to change 123 to ABC or ABC to 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++;
        }

    }

}

output:

enter image description here

Kirit Modi
  • 23,155
  • 15
  • 89
  • 112
  • thanks for the replay but i have already set it . i want to know about special character. like when you click on 123 the special character key shown in place of caps button and when you click on it special character like $ , euro or pound etc load and 123 set in place of special character . and when you click ABC then again Caps key appear . please check in image . – Badal Shah Aug 17 '15 at 11:24
  • what happen when you click on special character button ? – Badal Shah Aug 17 '15 at 11:33
  • same login make one array of symbols. – Kirit Modi Aug 17 '15 at 11:40
  • thanks your answer help me a lot. still i post my methods how i set this . – Badal Shah Aug 17 '15 at 13:50
1

I have set my problem with this way because i set images of keys also .

  @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];

    }
Badal Shah
  • 7,541
  • 2
  • 30
  • 65