Posts

Post not yet marked as solved
1 Replies
2.1k Views
We have implemented a code to add a link to the whole attributed text inside a UITextView.The strings we are loading are:English String: "Click Here To View"Arabic String: {some Arabic text}Code:func setupTextView() { let mutableAttributedString = NSMutableAttributedString(string: "") let attributedString = NSAttributedString(string: {string value}, attributes: [NSAttributedString.Key.foregroundColor:Colors.gray_3_748499]) mutableAttributedString.append(attributedString) mutableAttributedString.addAttribute(NSAttributedString.Key.link, value: "https://www.google.com", range: NSMakeRange(0, self.attributedString.length)) self.textView.attributedText = mutableAttributedString }Result:We can see that the delegatetextView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction)is not called when the text added in the text view in Arabic language.For all other languages (left to right) the delegate gets fired.Looking forward for valuable suggestions.
Posted Last updated
.
Post not yet marked as solved
8 Replies
4.3k Views
The title says it all. These are my development setup1) Xcode 112) A simple project targeting iOS 133) 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 belowimport 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.
Posted Last updated
.