Right aligned UITextField spacebar does not advance cursor in iOS 7

前端 未结 14 1696
执笔经年
执笔经年 2020-12-07 23:04

In my iPad app, I noticed different behavior between iOS 6 and iOS 7 with UITextFields.

I create the UITextField as follows:

UIButton *theButton = (U         


        
14条回答
  •  一向
    一向 (楼主)
    2020-12-07 23:27

    Swift 4 version:

    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool{
        if var text = textField.text, range.location == text.count, string == " " {
            let noBreakSpace: Character = "\u{00a0}"
            text.append(noBreakSpace)
            textField.text = text
            return false
        }
        return true
    }
    

提交回复
热议问题