iOS在UIWebView表单输入中使用UIKeyboardTypeDecimalPad [英] iOS use UIKeyboardTypeDecimalPad in UIWebView form input

查看:72
本文介绍了iOS在UIWebView表单输入中使用UIKeyboardTypeDecimalPad的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示在基于Cordova的应用程序中本机应用程序使用的左角带有小数点的小写字母。

I want to show the decimal pad with a '.' in the left corner used by native apps in a cordova based app.

我已经看到很多使用私有API等的线程。但是我想要一个可以提交应用商店的解决方案。

I have seen a lot of threads using private APIs etc. but I want a solution that would go for app store submission. Any help is appreciated.

我已经尝试了线程。

I have already tried something from this thread.

下面是我的修改,

@protocol TSPingPong <NSObject>
- (void) ts_pong: (id) sender;
@end

@interface NSObject (TSPingPong)
@end
@implementation NSObject (TSPingPong)
- (void) ts_ping: (id) sender
{
    if ( [sender respondsToSelector: @selector(ts_pong:)] )
    {
        [sender performSelector: @selector( ts_pong: ) withObject: self ];
    }
}
@end


@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIWebView *webView;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver: self
                                             selector: @selector(keyboardWillAppear:)
                                                 name: UIKeyboardWillShowNotification
                                               object: nil];

    NSString* html = @"<br><br><br><form action=''> " \
    "First name: <input type='text'><br> " \
    "Last name: <input type='text'><br>" \
    "<input type='submit' value='Submit'> " \
    "</form>";

    [_webView loadHTMLString: html
                     baseURL: nil];
}

- (void) keyboardWillAppear: (NSNotification*) n
{
    // the keyboard is about to appear!
    // play pingpong with the first responder so we can ensure it has a keyboardAppearance method:

    [[UIApplication sharedApplication] sendAction: @selector( ts_ping:) // added via category extension
                                               to: nil                  // to: the first responder
                                             from: self                 // "sender"
                                         forEvent: nil];
}

- (void) ts_pong: (id) sender
{
    // sender is the first responder.  Happens to be undocumented "UIWebBrowserView" in this case.

    // if it doesn't have it's own keyboardAppearance method then let's add one:
    if ( ![sender respondsToSelector: @selector(keyboardAppearance)] )
    {
        Method m = class_getInstanceMethod( [self class], @selector( keyboardAppearanceTemplateMethod ) );

        IMP imp = method_getImplementation( m );

        const char* typeEncoding = method_getTypeEncoding( m );

        class_addMethod( [sender class], @selector(keyboardAppearance), imp, typeEncoding );

    }

    if ( ![sender respondsToSelector: @selector(keyboardType)] )
    {
        Method m1 = class_getInstanceMethod( [self class], @selector( keyboardTypeTemplateMethod ) );

        IMP imp1= method_getImplementation( m1 );

        const char* typeEncoding1 = method_getTypeEncoding( m1 );

        class_addMethod( [sender class], @selector(keyboardType), imp1, typeEncoding1 );

    }
}

- (UIKeyboardAppearance) keyboardAppearanceTemplateMethod
{
    return UIKeyboardAppearanceDark;
}


- (UIKeyboardType)keyboardTypeTemplateMethod
{
    return UIKeyboardTypeDecimalPad;
}

我能够使键盘外观变暗,但不能使键盘类型变暗

I am able to get the keyboard appearance to be dark but not the keyboard type which I desire.

我到目前为止看到的其他主题和答案,但没有结果,

Other threads and answers that I have seen so far but no results,

用户在UIWebView中点击时默认键盘如何出现?

> https://www.aerych.com/blog/2012/04/29/uiwebviews-uikeyboards-and-uitoolbars-oh-my/

如何设置自定义UIWebView的键盘

将自定义UIButton添加到UIKeyboard的附件视图中用于UIWebView

https:// github.com/dcorbatta/CKWebView

推荐答案

为此提供了一个新插件:

https://github.com/mnill/cordova-custom-keyboard

There is a new plugin for this:
https://github.com/mnill/cordova-custom-keyboard

这篇关于iOS在UIWebView表单输入中使用UIKeyboardTypeDecimalPad的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆