iOS开发之自定义键盘附件关闭虚拟键盘

//

//  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开发之自定义键盘附件关闭虚拟键盘_第1张图片


你可能感兴趣的:(iOS开发之自定义键盘附件关闭虚拟键盘)