首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在of键盘顶部添加工具栏

在of键盘顶部添加工具栏
EN

Stack Overflow用户
提问于 2012-01-25 13:11:31
回答 4查看 20.4K关注 0票数 17

我有一个工具栏,我想把它放在键盘上。

在键盘将显示通知中,我尝试添加工具栏到键盘,但没有成功,我不能添加

请让我知道

代码语言:javascript
复制
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];
        }
    }
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-01-25 13:22:00

我想,你想要一个inputAccessoryView

基本上,您创建一个视图并将其设置为文本字段或文本视图的输入附件视图。

代码语言:javascript
复制
[textField setInputAccessoryView:inputAccessoryView];
票数 44
EN

Stack Overflow用户

发布于 2012-07-25 19:23:18

下面是一些代码,以防其他人在堆栈溢出时需要使用it.Found

代码语言:javascript
复制
- (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];
}
票数 15
EN

Stack Overflow用户

发布于 2014-12-21 23:26:13

https://github.com/asefnoor/IQKeyboardManager

这是我见过的最好的键盘处理程序。管理文本输入的非常好的方式。

它的一些特性1)零行代码

2)自动工作

3)不再使用UIScrollView

4)不再有子类

5)不再需要手工操作

6)不再有#imports

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8998134

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档