The title says it all. These are my development setup
1) Xcode 11
2) A simple project targeting iOS 13
3) An iPhone 8 running iOS 13.1.2 (17A860)
I created a new Project in Xcode 11, a simple View controller that contains a UITextView. The TextView has autoCapitalizationType as "Sentences". Then I implemented the delegate method "shouldChangeTextInRange" method. See the code below
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var textView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
self.textView.delegate = self
self.textView.autocapitalizationType = .sentences
}
}
extension ViewController: UITextViewDelegate {
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
//I wanted to do some other modifications here, but for now just setting the text manually and returning false
if let oldString = textView.text {
let newString = oldString.replacingCharacters(in: Range(range, in: oldString)!,
with: text)
textView.text = newString
}
return false
}
}
As you can see above, I am just manually setting the same text that is entered by user in shouldChangeTextInRange method and return false. But when I type, the first character gets added in caps as it should. The second character correctly gets added in small letter. From third character onwards everything is caps. More over, the keyboard Caps button automatically getting selected after each characters is typed.
This is only on iOS 13. I didn't get this in previous iOS versions. And it is not happening for other autocapitalizationType values like Words, None etc. I tried to set autocapitalizationType in code and in storyboard, with same results.
Let us know if any other information is needed. Thanks in advance.