如何检测iOS键盘中UITextField的大写锁定键?

问题描述 投票:0回答:1

如何检测用户是否点击了iOS键盘上的大写锁定按钮?

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {

        print(string)
        return true

    }

此方法用于在textField中更改文本。还有其他方法吗?

为什么我想知道是否按下了大写锁定按钮,是因为当用户轻按大写锁定按钮时,我的右视图和苹果的大写锁定图标重叠了。

ios swift uitextfield uitextfielddelegate
1个回答
0
投票

[无论何时按下大写锁定,iOS都会在shift-up的右侧显示UITextField符号。如果您看到视图层次结构,则大写锁定图标基本上将设置在UITextField的rightView内部。

enter image description here

因此,将rightView设置为UIView,且framezero

myTextField.rightView = UIView(frame: .zero)
© www.soinside.com 2019 - 2024. All rights reserved.