Posts

Post marked as solved
4 Replies
1.4k Views
I have been trying to change the title of my UIButton every iteration of a for loop in swift, but it doesn't work as the titles are not being updated. Heres the code:@IBOutlet var generateButton: UIButton! var x: Double = 0.0 for i in 0...nTokens { x = (Double(i)/Double(nTokens)) * 100 print(self.generateButton.isHighlighted) self.generateButton.setTitle("\(x) %", for: .highlighted) self.generateButton.titleLabel!.font = UIFont.systemFont(ofSize: 20) sleep(3) }Have already linked generateButton to the correct button in the view, and self.generateButton.isHighlighted always print true. What am I doing wrong? Thanks
Posted
by plkmo.
Last updated
.
Post marked as solved
4 Replies
2.6k Views
I am trying to replace user input text with some edited text. I have implemented the below function to do this:func replaceText(replacementString string: String) { if let afterInput = textDocumentProxy.documentContextAfterInput { textDocumentProxy.adjustTextPosition(byCharacterOffset: afterInput.count) } if let word:String = textDocumentProxy.documentContextBeforeInput { for _: Int in 0 ..< word.count { textDocumentProxy.deleteBackward() } } textDocumentProxy.insertText(string) }Thereafter, I will use this as follows to replace text in any user input string:delegate?.replaceText(replacementString: "Test")where delegate points to the keyboard viewcontroller.Input -> Output ( | denotes the cursor position):Zxzxzxzxzx| -> Test|Zxzxzxzxzx😉zxc -> Test|xcHowever, it doesn't seem to work as planned, as you can see from the above input -> output.Eg. For normal text without emojis, "Zxzxzxzxzx" gets replaced by "Test" as expected. But with emoji, "Zxzxzxzxzx😉zxc" gets replaced by "Test|xc", and the cursor is now in the middle of the text.It seems to break when emojis are present in the text. I have printed out the word counts and it seems consistent. Any ideas? Thanks in advance.
Posted
by plkmo.
Last updated
.