iphone - iPhone虚拟键盘添加新按钮?

标签 iphone objective-c ios

如何在iPhone的虚拟键盘(触摸UITextField时出现的键盘)中添加新按钮?

最佳答案

这是我在键盘左下角添加完成按钮的代码。

您需要做的就是借鉴 thiis 的想法,并将按钮设置在键盘上您想要的任何位置。

- (void)keyboardWillShow:(NSNotification *)note {
    // create custom button
    UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
    doneButton.frame = CGRectMake(0, 163, 106, 53);
    doneButton.adjustsImageWhenHighlighted = NO;
    [doneButton setTitle:@"Done" forState:UIControlStateNormal];
    //[doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
    //[doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
    [doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];

    // locate keyboard view
    UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
    for(int i=0; i<[tempWindow.subviews count]; i++) {
        keyboard = [tempWindow.subviews objectAtIndex:i];
        // keyboard view found; add the custom button to it
        if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
        {
            if(isNumPad==YES)
            {
                //[keyboard addSubview:doneButton]; 
            }
            else
            {
                [doneButton removeFromSuperview];
            }
        }
        else 
        { 
            [doneButton removeFromSuperview];

        }}
}
- (void)doneButton:(id)sender 
{

//YOUR CODE ON DONE BUTTON CLICKED
}

快乐编码...

关于iphone - iPhone虚拟键盘添加新按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3956648/

相关文章:

iphone - 屏幕旋转处理ios

iphone - 更改 UIImage(不是 UIImageView)的透明度

objective-c - CATiledLayer : Render zoomable PDF Page - what are "LevelsOfDetail" and "LevelsOfDetailBias"?

objective-c - 在 SQLite 数据库中保存经度和纬度

ios - UItextfields 之间的 UIToolbar 导航

iphone - 自定义 UITableViewCell 为空,尽管 heightForRowAtIndexPath 中的单元格是正确的

iphone - C 中的快速 4x4 矩阵乘法

ios - 具有数字和可比较协议(protocol)的 Swift 泛型类

ios - MPMediaPickerController 显示白屏,没有错误

iphone - 如何计算NSString对象中非字母数字字符的数量?