//
// ViewController.m
// 1113自定义键盘附件关闭虚拟键盘
//
// Created by weibiao on 15/11/13.
// Copyright © 2015年 weibiao. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextView *textView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 设置UIToolBar工具条
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
// 设置工具条的样式
[toolBar setBarStyle:UIBarStyleDefault];
// create first button for toolBar
UIBarButtonItem *myBtn = [[UIBarButtonItem alloc] initWithTitle:@"无动作" style:UIBarButtonItemStylePlain target:self action:nil];
// create second button for toolbar
UIBarButtonItem *spaceBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
// create three button for toolbar
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(editFinish)];
// add the btn for toolbar
NSArray *btnArrays = [NSArray arrayWithObjects:myBtn,spaceBtn,doneBtn, nil];
[toolBar setItems:btnArrays];
// 为textView关联的虚拟键盘设置 附件
[self.textView setInputAccessoryView:toolBar];
}
- (void)editFinish {
[self.textView resignFirstResponder];
}
@end
本文介绍如何在iOS应用中通过自定义键盘附件实现点击完成按钮后关闭虚拟键盘的方法。文章展示了如何创建并配置一个包含完成按钮的工具条,以及如何通过简单的Objective-C代码实现该功能。
16

被折叠的 条评论
为什么被折叠?



