将自定义UIButton添加到UIKeyboard的UIWebView的附件视图 [英] Add custom UIButton to UIKeyboard's accessory view for a UIWebView

查看:159
本文介绍了将自定义UIButton添加到UIKeyboard的UIWebView的附件视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要向 UIWebView 的键盘附件视图工具栏(已经有后退|下一步和完成按钮的工具栏)添加一个相机按钮。 。



有没有简单的方法来做到这一点?

解决方案

有更简单的方法。



viewDidLoad

$ b中保留键盘通知
$ b

之后,您需要的是以下方法:

   - (void)keyboardDidShow: (NSNotification *)notif 
{
NSArray * array = [[UIApplication sharedApplication] windows];

for(UIWindow * wind in array){
for(UIView * currView in wind.subviews){
if([[currView description] hasPrefix:@< UIPeripheralHostView ]){
for(UIView * perView in currView.subviews){
if([[perView description] hasPrefix:@< UIWebFormAccessory]){

UIBarButtonItem * doneBttn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(resignKeyBoard)];

NSMutableArray * arr = [[NSMutableArray alloc] initWithArray:[(UIToolbar *)perView items]];

[arr addObject:doneBttn];

[(UIToolbar *)perView setItems:arr];
}
}

}
}
}
}

我基本上使用了UIWebFormAccessory中的原来的prev / next按钮,并在它的末尾添加了一个done按钮,但你可以添加你想要的按钮。 / p>

有些人可能认为这不应该在 - (void)keyboardDidShow:它显示在屏幕上,但到目前为止我还没有注意到这个问题。 (仅在模拟器中测试)



希望这很有用!


I need to add a camera button to a UIWebView's keyboard accessory view toolbar (the one that already has the "Back|Next" and "Done" buttons).

Is there an easy way to do this?

解决方案

there is an easier way to do this.

Keep your keyboard notification in your viewDidLoad

After that all you will need is the following method:

-(void)keyboardDidShow:(NSNotification*)notif
{
    NSArray *array = [[UIApplication sharedApplication] windows];

    for (UIWindow* wind in array) {
        for (UIView* currView in wind.subviews) {
            if ([[currView description] hasPrefix:@"<UIPeripheralHostView"]) {
                for (UIView* perView in currView.subviews) {
                    if ([[perView description] hasPrefix:@"<UIWebFormAccessory"]) {

                        UIBarButtonItem *doneBttn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(resignKeyBoard)];

                        NSMutableArray *arr = [[NSMutableArray alloc] initWithArray: [(UIToolbar *) perView items]];

                    [arr addObject:doneBttn];

                    [(UIToolbar *) perView setItems:arr];
                    }
                }

            }
        }
    }
}

I have basically taken the original prev/next buttons from the UIWebFormAccessory and added a done button to the end of it, but you can add what ever buttons you want to this.

Some may think this shouldn't be implemented in -(void)keyboardDidShow: because you are changing the UI after it displays on screen, but so far I haven't noticed any issues with this. (only tested in simulator)

Hope this was useful!

这篇关于将自定义UIButton添加到UIKeyboard的UIWebView的附件视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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