美文网首页
与键盘的那点事

与键盘的那点事

作者: 王欣12138 | 来源:发表于2016-06-25 08:04 被阅读14次

    1.自定义键盘

    ```

    self.view.inputView:

    ```

    2.退出键盘

    ```

    1> [self resignFristResponer];

    2>[self.view endEdting];

    ```

    3.退出自定义键盘

    ```

    self.view.inputView =nil;

    //清空自定义键盘,系统视作恢复系统自带键盘

    textfield= [[UITextFieldalloc]initWithFrame:CGRectMake(100,100,100,100)];

    textfield.backgroundColor= [UIColorredColor];

    [self.viewaddSubview:textfield];

    UIToolbar* topView = [[UIToolbaralloc]initWithFrame:CGRectMake(0,0,320,30)];

    [topViewsetBarStyle:UIBarStyleBlackTranslucent];

    //让键盘在右边,创建一个空的按钮

    UIBarButtonItem* btnSpace = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpacetarget:selfaction:nil];

    UIButton*btn = [UIButtonbuttonWithType:UIButtonTypeCustom];

    btn.frame=CGRectMake(2,5,100,25);

    [btnsetTitle:@"键盘收起"forState:UIControlStateNormal];

    [btnaddTarget:selfaction:@selector(dismissKeyBoard)forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem*doneBtn = [[UIBarButtonItemalloc]initWithCustomView:btn];

    NSArray* buttonsArray = [NSArrayarrayWithObjects:btnSpace,doneBtn,nil];

    [topViewsetItems:buttonsArray];

    [textfieldsetInputAccessoryView:topView];

    }

    -(void)dismissKeyBoard

    {

    [textfieldresignFirstResponder];

    }

    ```

    相关文章

      网友评论

          本文标题:与键盘的那点事

          本文链接:https://www.haomeiwen.com/subject/rgqadttx.html