How to connect UITextView to a home made keyboard? - ios

I have a UITextView field meant to receive input from a keyboard.
But the standard keyboard not being adequate for my app, I built another one with the buttons and characters I need.
I would normally make use of the UITextViewDelegate protocol and things would work.
But in this situation, how do I connect the UITextView field and my new keyboard?
Is there a "best way to do it"?
Thanks in advance for any relevant information.

Set your custom view as inputView of the UITextView.
// Edit: additional information:
Your custom keyboard will be a collection of buttons. You can add the same selector as target for all those buttons. Than your callback could be:
- (void) buttonTouched: (UIButton*) button
{
myTextView.text = [myTextView.text stringByAppendingString: button.text];
}

Related

Custom Keyboard on iOS

I need to create a custom keyboard for my app, but no sure the best way to do it without the user needing to add a keyboard in the settings. If I create a keyboard extension is it possible to set a UITextField's Keyboard Type to that custom keyboard? Or will I have to use a UIView to accomplish this?
For a custom keyboard that is specific to a single app, create a view and assign the view to UITextField.inputView:
textField.inputView = YourCustomKeyboard()
In my search I didn't find a way to tack on additional keys but there are examples of custom keyboards using inputView that are easy to adapt.
A custom decimal keyboard example
My hexadecimal keyboard version
You can add accessoryView to text view for you want to give a few extra buttons.
If you still looking for some more then please go through the below link.
https://www.cocoacontrols.com/search?utf8=%E2%9C%93&q=keyboard

[Objective-C]Edit UILabel without hiding keyboard

Im trying to copy the content in a UILabel but without hiding the keyboard, the problem is that when I show the menu of copy in the label the label becomes first responder and the keyboard resign, but I want to do that without hiding the keyboard, is there a way to do that?
It is not possible with UILabel.
You should use UITextField for that. Just disable editing.
AFAIK, you can't do that. But I think you can have a work around for that. Instead of not hiding the keyboard, why don't keep track the current active text field and then active it after user press copy. You can use UIPasteboardChangedNotification to know when user pressed copy. For example:
self.lastActiveTextField = aTextField
-(void)pasteBoardDidChange:(NSNotification*)notif
{
[self.lastActiveTextField becomeFirstResponder];
}
I think so u r looking something like this project.
UILabel with UIKeyInput protocol implementation
https://github.com/hackiftekhar/IQEditableLabel
I think, it is not possible, there can be only one first responder at any time. If the keyboard is shown because of another UI element, then when you try to copy the content from UILabel, the OS has to transfer first responder from other element to UILabel, as there is no need of keyboard for UILabel, the keyboard will hide automatically. So, you have to make changes to your elements to fix this problem or use third party UI elements who can fix your problem.
Every UIView component has a method called: canBecomeFirstResponder. He is read only, but you can subclass the UI object and override the getter:
- (BOOL)canBecomeFirstResponder {
return false;
}
I didn't do the test, but if the "become first responder" is the problem, that should solve it.

Trying to implemen custom number pad for UITextField in iOS

I am working on an app where I have a UITableView that has a UITextField in each cell. The textfield is attached to each row via a custom cell. Because there is no number only keypad for the iPad, I have to implement my own (I don't have a choice here). I have created custom buttons for this keyboard inside MainStoryboard, attached these buttons to a view that serves as a custom inputView. These buttons all call the same method which should enter the value of the label on the button, into the textfield. Unfortunately, this is not working. I am implementing the UITextFieldDelegate method:
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
NSLog(#"how about here?");
return YES;
}
which unfortunately does not get called when I place the cursor in any of the textfields, and not when I press any of the keys on the keypad, since I don't see any output on my xcode screen.
I attach the custom keypad to the inputView attribute of each textfield inside my "cellForRowAtIndexPath" method as follows:
_cell.textField.inputView = _inputView;
Can anyone see what I'm doing wrong? I figure implementing the UITextFieldDelegate would be the way to go to accomplish this (which to me appears to be very straight forward), but unfortunately I'm struggling with this. I have also included a screenshot if it helps.
Thanks in advance to all who reply.
Make
textField.delegate = self
or
_cell.textField.delegate = self;
Hope this works !!!

Accessible Custom Keyboard in iOS

I want to make a custom keyboard perform like the iOS software keyboard with regards to accessibility. When a button-press adds a letter to a UITextField, the letter should be spoken by VoiceOver in the ‘added character tone‘. When a button-press deletes a letter from a UITextField, the letter should be spoken by VoiceOver in the ‘deleted character tone’.
Here is what I attempted:
Created a UITextField in the view controller, in the storyboard.
Created two UIButtons labeled ‘Type’ and ‘Backspace’ in the view controller, in the storyboard.
Set the accessibility traits for both UIButtons to Keyboard Key.
Hooked the storyboard UITextField up to an IBOutlet UITextField instance, textField.
Hooked the storyboard ‘Type’ UIButton up to an IBAction, -type.
Hooked the storyboard ‘Backspace’ UIButton up to an IBAction, -backspace.
Implemented -type as: [[self textField] insertText:#"a"];.
Implemented -backspace as: [[self textField] deleteBackward];.
Made textField the first responder.
I also tried the same thing, moving the buttons into a UIView that was set as textField’s inputView.
The characters are properly added to and removed from the text field, but they are not spoken by VoiceOver. How can I make this work?
EDIT:
The hardware keyboard speaks correctly. It is only the custom software keyboard that is not speaking as it should.
I noticed that to get “Spoken Content” » “Speak Screen” to speak the keyboard keys, too, I had to add the .keyboardKey to the button accessibilityTraits, e.g. in Swift:
button.accessibilityTraits = [.keyboardKey]
Or in Objective-C:
[button setAccessibilityTraits:UIAccessibilityTraitKeyboardKey];
And, obviously, if your buttons are images, you’ll want to add explicit accessibilityLabel for them, too.
Voice Over may need to be enabled for the whole device for this to work. You can change this in accessibility. I'm not ure what to do if voice over is already enabled on the device.

Click a button to show the keyboard iOS

I want to realize the function: when I click a button, a interface of keyboard will come out in a dependent interface. How can I do it? Just for iOS.
You need to add to your current view UITextField with frame = CGRectZero, create a reference to that textField in code and then on pressing button call becomeFirstResponder on textField.
You need to add an UITextField to your view and call then [myTextfield becomeFirstResponder]; Its possible to set the hidden attrribute from UITextField to YES - so the user will never see the textfield. After Keyboard input is finished you can remove the UITextField with removeFromSuperview.
Maybe a little bit dirty,but thats the solution I used often. I wonder if the SDK provide another possibility.

Resources