NumberPad for iPad? - ios

I set Number Pad for my TextField on the Storyboard, because I need only numbers for my app. But it works for iPhone only. I can't find solution for iPad. I tried
override func viewDidLoad() {
super.viewDidLoad()
self.myTextField.keyboardType = .numberPad
but it doesn't work. Help me please.

iPad doesn't have number only keyboard. You should implement your own. There are some git projects you can use like these:
- Some Swift Repositories:
NumericKeyboard
NumPad
NumberPad
KBNumberPad
- Some Objective-c Repositories:
HSNumericField
NumericKeypad
NumberPad

Related

UITextView as inputAccessoryView like iMessage

I want to have the same kind of behaviour as iMessage has for its input. I don't know in what end I should start, so I'll describe what I want to do and you can (I hope) give me suggestions on how to do this. I code in Swift so I'd like it to be in Swift if you provide any code.
What I want
I want to have a button on my screen (not an UITextView or UITextField) which upon press shows the keyboard, and where the keyboard has a UIToolBar with an UITextView in it. When I type in the UITextView the ToolBar/TextView expands up until a certain point then it starts to scroll.
How on earth do I do this? I've been trying for an hour but I can't seem to trigger the keyboard unless I have a UITextView or UITextField to set as becomeFirstResponder(). Furthermore I don't understand how I'm supposed to attach a UITextView to the UIToolBar once I get the keyboard up. I have added the UIToolBar, but not the UITextField.
Cheers
This should do it for you: https://github.com/AlexLittlejohn/ALTextInputBar
It grows like you mentioned, and it's also at the bottom of screen, like an input accessory view.
In your pods file copy paste
pod 'ALTextInputBar'
Run your podfile
Configure it like this
import ALTextInputBar
class ViewController: UIViewController {
let textInputBar = ALTextInputBar()
// The magic sauce
// This is how we attach the input bar to the keyboard
override var inputAccessoryView: UIView? {
get {
return textInputBar
}
}
// Another ingredient in the magic sauce
override func canBecomeFirstResponder() -> Bool {
return true
}
}

Adding Return Button In Keyboard Extension

I am making a customized iOS 8 keyboard. I created a button called Return and I'm stuck because I don't know how to make Return or Enter key work properly. I found many textFielsShouldReturn tutorials but I don't think it belongs to iOS keyboard extensions.
Okay. I got it so easy in short time. This is what i did.
#IBAction func returnPressed(sender: AnyObject) {
var proxy = textDocumentProxy as UITextDocumentProxy
proxy.insertText("\n")
}

how to detect Number and Decimal Keyboard iOS

I'm developing a custom keyboard and based on Apple App Store Review guideline I have to provide a keypad for decimal and number pad :
Keyboard extensions must provide Number and Decimal keyboard types as described in the App Extension Programming Guide or they will be rejected
So I have to provide a keyboard for Decimal and Number Textfield, so how can I detect textfield type.
There is nothing about Number or Decimal Keyboard in App Extension Programming Guide so How detect which textfield I should load Decimal Keyboard or Number Keypad ?
You can get the current keyboard type before your view appears like so (in Swift).
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
// Setup keyboard manager to correct type
if let inputTraits = self.textDocumentProxy as? UITextInputTraits {
let keyboardType = inputTraits.keyboardType
let returnKeyType = inputTraits.returnKeyType
}
}
This from my project but reformatted for clarity. I also didn't compile it since it's such a simple example.
I've found it's good not to trust any extension API values until the view is visible or about to appear, but you could also try this in viewDidLoad()

How can I add a Number and Decimal keyboard into my Custom Keyboard on iOS8?

I created a custom keyboard in Swift but it was rejected from the App Store because: "keyboard extension does not include Number and Decimal types".
How can I add these two keyboards easily?
I tried to rebuild the original view but it doesn't work properly. I'm sure there is a solution to create 2 or 3 different views and switch between them.
How can I switch between keyboard types when the keyboard type changes?
You can detect changes to the keyboard type in textDidChange. You need to get the UITextDocumentProxy then detect the proxy's keyboardType, and then you can do whatever layout changes needed.
override func textDidChange(_ textInput: UITextInput?) {
// Called when the document context is changed - theme or keyboard type changes
let proxy = self.textDocumentProxy as UITextDocumentProxy
if proxy.keyboardType == UIKeyboardType.numberPad
|| proxy.keyboardType == UIKeyboardType.decimalPad {
//add code here to display number/decimal input keyboard
}
}

How do I connect custom keyboard to text field?

I created a custom keyboard using buttons, but now I'm stuck with buttons that don't do anything.
How will I connect them to a text field?
First, you should be aware of the inputView property of the UITextField/UITextView classes. Basically you can have a custom view (your keyboard for example) and swap it with the default keyboard.
You can get some inspiration from this tutorial that shows how to create a custom keyboard - and how to connect it to your textfield/textview.
You can also read this answer for another way to connect your keyboard to a textfield/textview.
You can handle buttons touchUpInside Action like this to insert text in uitextfield
#IBAction func btnQuestionAction(_ sender: UIButton)
{
self.textDocumentProxy.insertText("?")
}
And to delete character using custom keyboard, You can use this:
#IBAction func btnBackspaceAction(_ sender: UIButton)
{
self.textDocumentProxy.deleteBackward()
}
Hope it will help you :)

Resources