Right aligned UITextField spacebar does not advance cursor in iOS 7

前端 未结 14 1722
执笔经年
执笔经年 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:38

    I've used Jack Song's answer for Swift 2 for a while until I realized that the non-braking spaces make problems when rendered in HTML elsewhere, as well as line breaking gets messy in the UITextView itself. So, I've improved the solution to have the non-bracking characters cleaned right away.

    func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
        if (textField == self.desiredTextField) {
           var oldString = textView.text!
           oldString = oldString.stringByReplacingOccurrencesOfString("\u{00a0}", withString: " ");
           let newRange = oldString.startIndex.advancedBy(range.location)..

提交回复
热议问题