我有一个工具栏,我想把它放在键盘上。
在键盘将显示通知中,我尝试添加工具栏到键盘,但没有成功,我不能添加
请让我知道
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i = 0; i < [tempWindow.subviews count]; i++)
{
//Get a reference of the current view
keyboard = [tempWindow.subviews objectAtIndex:i];
//Check to see if the description of the view we have referenced is "UIKeyboard" if so then we found
//the keyboard view that we were looking for
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
{
[keyboard addSubview:myToolbar];
}
}
发布于 2012-01-25 13:22:00
我想,你想要一个inputAccessoryView。
基本上,您创建一个视图并将其设置为文本字段或文本视图的输入附件视图。
[textField setInputAccessoryView:inputAccessoryView];
发布于 2012-07-25 19:23:18
下面是一些代码,以防其他人在堆栈溢出时需要使用it.Found
- (void)viewDidLoad
{
[super viewDidLoad];
UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
numberToolbar.barStyle = UIBarStyleBlackTranslucent;
numberToolbar.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:@"Clear" style:UIBarButtonItemStyleBordered target:self action:@selector(clearNumberPad)],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:@"Apply" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)],
nil];
[numberToolbar sizeToFit];
numberTextField.inputAccessoryView = numberToolbar;
}
-(void)clearNumberPad{
[numberTextField resignFirstResponder];
numberTextField.text = @"";
}
-(void)doneWithNumberPad{
NSString *numberFromTheKeyboard = numberTextField.text;
[numberTextField resignFirstResponder];
}
发布于 2014-12-21 23:26:13
https://github.com/asefnoor/IQKeyboardManager
这是我见过的最好的键盘处理程序。管理文本输入的非常好的方式。
它的一些特性1)零行代码
2)自动工作
3)不再使用UIScrollView
4)不再有子类
5)不再需要手工操作
6)不再有#imports
https://stackoverflow.com/questions/8998134
复制相似问题