键盘不显示带有UITextFields的语言切换按钮(globe)

时间:2020-03-11 07:21:57

标签: ios swift iphone

我在一个UIViewController中有2个UITextField。

第一个是电子邮件。聚焦后,键盘上将显示语言切换按钮(globe)。 EMail UITextField with Keyboard

第二个是昵称。当它聚焦时,键盘将显示没有地球按钮。 Nickaame UITextField with Keyboard

这两个UITextField之间的代码几乎相同。即使我将昵称UITextField更改为电子邮件UITextField的键盘类型,它也不会显示地球按钮。我不知道为什么第二个UITextField总是不显示Globe按钮。

代码如下:

        mEmail = UITextField(frame: CGRect(x: PADDING,
                                           y: innerY,
                                           width: mInputArea!.bounds.width - PADDING*2,
                                           height: 40))
        mEmail!.textContentType = .emailAddress
        mEmail!.autocapitalizationType = .none
        mEmail!.keyboardType = .emailAddress
        mEmail!.layer.borderColor = ColorDef.background.cgColor
        mEmail!.layer.borderWidth = 1
        mEmail!.layer.cornerRadius = 4
        mEmail!.placeholder = localizedInfoPlist("Account_Email")
        mEmail!.clearButtonMode = .whileEditing
        mEmail!.returnKeyType = .next
        mEmail!.delegate = self
        mInputArea!.addSubview(mEmail!)
        innerY += (PADDING + mEmail!.bounds.height)

        mName = UITextField(frame: CGRect(x: PADDING,
                                          y: innerY,
                                          width: mEmail!.bounds.width,
                                          height: mEmail!.bounds.height))
        mName!.textContentType = .nickname
        mName!.autocapitalizationType = .none
        mName!.keyboardType = .default
        mName!.layer.borderColor = ColorDef.background.cgColor
        mName!.layer.borderWidth = 1
        mName!.layer.cornerRadius = 4
        mName!.placeholder = localizedInfoPlist("Nickname")
        mName!.clearButtonMode = .whileEditing
        mName!.returnKeyType = .next
        mName!.delegate = self
        mInputArea!.addSubview(mName!)
        innerY += (PADDING + mEmail!.bounds.height)

如何获取带有昵称UITextField的键盘中的地球按钮?

2 个答案:

答案 0 :(得分:0)

尝试一下

import UIKit

class ViewController: UIViewController, UITextFieldDelegate {

    @IBOutlet weak var mEmail: UITextField!
    @IBOutlet weak var mName: UITextField!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.

        mEmail!.textContentType = .emailAddress
        mEmail!.autocapitalizationType = .none
        mEmail!.keyboardType = .emailAddress
        mEmail!.layer.borderWidth = 1
        mEmail!.layer.cornerRadius = 4
        mEmail!.placeholder = "Account_Email"
        mEmail!.clearButtonMode = .whileEditing
        mEmail!.returnKeyType = .next
        mEmail!.delegate = self

        mName!.textContentType = .nickname
        mName!.autocapitalizationType = .none
        mName!.keyboardType = .default
        mName!.layer.borderWidth = 1
        mName!.layer.cornerRadius = 4
        mName!.placeholder = "Nickname"
        mName!.clearButtonMode = .whileEditing
        mName!.returnKeyType = .next
        mName!.delegate = self
    }

    func textFieldShouldReturn(_ textField: UITextField) -> Bool
    {
        switch textField
        {
        case self.mEmail:
            self.mName.becomeFirstResponder()
            break
        default:
            textField.resignFirstResponder()
        }
        return true
    }
}

答案 1 :(得分:0)

我发现我的软键盘为英文和Gboard(谷歌键盘)。 当第二个UITextField处于焦点状态时,地球按钮不会显示。 我认为可能是Gboard不像iPhone的其他语言键盘那样算在内的问题。因此,我使用“ Apple iPhone键盘”添加了其他语言,然后显示了地球按钮。

相关问题