How to add a UIToolbar on top of UIKeyboard using

2019-05-20 01:41发布

问题:

I follow the example in Obj-C at Custom iPhone Keyboard for finding the UIKeyboard in the Windows SubViews, however, I don't know how to do this using MonoTouch. I don't know what the "description" is. If it is a property of UIView I cannot access it from MonoTouch???

Can someone please provide an example of finding the UIKeyboard as in the Obj-C sample but in C# for use in MonoTouch?

Thank you.

回答1:

I assume you're looking for the same thing as the keyboard in Safari (i.e. it has a small toolbar at the top that adds extra functionality, as seen on the far right image here )

In that case, what you're looking for is the Input Accessory View (iOS 3.2 and above). In Monotouch, the way to do this is to override Input Accessory View in your view controller. A simple example I've used before

public override UIView InputAccessoryView 
{
    get 
    {
        UIView dismiss = new UIView(new RectangleF(0,0,320,27));
        dismiss.BackgroundColor = UIColor.FromPatternImage(new UIImage("Images/accessoryBG.png"));          
        UIButton dismissBtn = new UIButton(new RectangleF(255, 2, 58, 23));
        dismissBtn.SetBackgroundImage(new UIImage("Images/dismissKeyboard.png"), UIControlState.Normal);        
        dismissBtn.TouchDown += delegate {
             subjectField.ResignFirstResponder();
        };
        dismiss.AddSubview(dismissBtn);
        return dismiss;
    }
}

This just creates a UIView across the top of the keyboard, you can then add whatever you'd like to the view as normal.