0

How do I (if possible) programmatically change a UITextView's input type? For example, switching between the keyboard type 'URL' instead of 'Phone Pad'.

This is where you would change it regularly:

enter image description here

Thank you.

EJZ
  • 1,142
  • 1
  • 7
  • 26

1 Answers1

0

Here is a solution from https://www.tutorialspoint.com/how-to-restrict-uitextfield-to-take-only-numbers-in-swift

import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
   @IBOutlet weak var tf: UITextField!
      override func viewDidLoad() {
         tf.delegate = self
         super.viewDidLoad()
      }
      func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
         if let x = string.rangeOfCharacter(from: NSCharacterSet.decimalDigits) {
            return true
         } else {
         return false
      }
   }
}
Ezi CS
  • 24
  • 6