美文网首页程序员
iOS UITextField、UITextview弹出键盘上添

iOS UITextField、UITextview弹出键盘上添

作者: 世玉茹花 | 来源:发表于2019-09-27 13:42 被阅读0次

    用于某些页面,弹出键盘无法轻易收回键盘,,可以添加此按钮,以方便某些占满的页面收回键盘。
    核心就是:textField.inputAccessoryView

    16_02_02__09_03_2019.jpg
     UIToolbar* keyboardDoneButtonView = [[UIToolbar alloc] init];
        
        keyboardDoneButtonView.barStyle = UIBarStyleDefault;
        
        keyboardDoneButtonView.translucent = YES;
        
        keyboardDoneButtonView.tintColor = nil;
        
        [keyboardDoneButtonView sizeToFit];
        
        UIBarButtonItem *SpaceButton=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; // 让完成按钮显示在右侧
        
        UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(pickerDoneClicked)];
        
        [keyboardDoneButtonView setItems:[NSArray arrayWithObjects:SpaceButton, doneButton, nil]];
        
        _textField.inputAccessoryView = keyboardDoneButtonView;
    

    相关文章

      网友评论

        本文标题:iOS UITextField、UITextview弹出键盘上添

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