如何使UITextField中的文本全部小写?

时间:2019-06-19 01:49:07

标签: ios swift firebase firebase-realtime-database uitextfield

我在firebase中有以下查询,用于搜索用户名。

        let ref = Database.database().reference().child("UsernameIndex")
    ref.queryOrdered(byChild: "username").queryStarting(atValue: username).queryEnding(atValue: username+"\u{f8ff}").observeSingleEvent(of: .value) { snap in

问题在于,如果我在任何时候键入大写字母,都不会搜索,那么我如何才能使所有字母大小写或使文本小写或使查询不区分大小写?

使文本变为小写的最佳方法是:

        searchField.autocapitalizationType = .none
    searchField.autocorrectionType = .no
    searchField.spellCheckingType = .no

但是,这仍然允许用户键入大写字母。

1 个答案:

答案 0 :(得分:2)

我只需要将文本转换为小写(searchField.text.lowercased())并允许用户键入大写字母即可。这样可以避免用户在尝试输入大写字母时感到沮丧。