How to make popup like keyboard characters in iOS8 custom keyboard?

后端 未结 2 1519
别那么骄傲
别那么骄傲 2020-12-13 20:46

I want to create popup in iOS8 custom keyboard as shown below image.

\"Want

2条回答
  •  暖寄归人
    2020-12-13 20:54

    This what i have done in my custom Keyboard its working

    //adding pop up when character is tapped
    - (void)addPopupToButton:(UIButton *)button
    {
    
    
        CGRect frame,frame1;
        if(self.view.frame.size.width == 320)
        {
            //Keyboard is in Portrait
            frame = CGRectMake(0, -25, 28, 43);
            frame1=CGRectMake(0, 0, 28, 43);
    
        }
        else{
            //Keyboard is in Landscape
            frame = CGRectMake(3, -25, 35, 43);
            frame1=CGRectMake(0, 10, 35, 43);
    
        }
       //create pop up view
        UIView *popUp=[[UIView alloc]initWithFrame:frame];
    
        //create a label to add to pop up view
        UILabel *text = [[UILabel alloc] init];
    
        //set frame for the label and set label title
        [text setFrame:frame1];
        [text setText:button.titleLabel.text];
        text.textAlignment=NSTextAlignmentCenter;
        [text setFont:[UIFont boldSystemFontOfSize:30]];
        text.backgroundColor=[UIColor whiteColor];
    
        //add label as popup view's subview
        [popUp addSubview:text];
    
        //add pop up view as button's subview
        [button addSubview:popUp];
    
    }
    
    
    //remove Pop up view
    -(void)endPopUpForButton:(UIButton*)button
    {
        if ([button subviews].count > 1)
        {
            [[[button subviews] objectAtIndex:1] removeFromSuperview];
        }
    }
    

    enter image description here

提交回复
热议问题