为虚拟键盘添加辅助控件

self.textView=[[UITextView alloc]initWithFrame:CGRectMake(0, 70 , 420, 850)];

UIToolbar* topView=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];

UIBarButtonItem* myBn=[[UIBarButtonItem alloc]

initWithTitle:@"无动作"

style:UIBarButtonItemStyleBordered

target:self

action:nil];

UIBarButtonItem* spaceBn=[[UIBarButtonItem alloc]

initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace

target:self action:nil];

UIBarButtonItem* doneBn=[[UIBarButtonItem alloc]

initWithTitle:@"完成"

style:UIBarButtonItemStyleDone

target:self

action:@selector((finishEdit))];

NSArray* buttonsArray=[NSArray arrayWithObjects:

myBn,spaceBn,doneBn, nil];

[topView setItems:buttonsArray];

[self.textView setInputAccessoryView:topView];

你可能感兴趣的:(为虚拟键盘添加辅助控件)