Created
August 14, 2023 03:23
-
-
Save DisappearPing/1bf02032b171df81ccca108559dccf2b to your computer and use it in GitHub Desktop.
強置換行加點
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { | |
if text == "\n" { | |
let nsString = textView.text as NSString? | |
let newString = nsString?.replacingCharacters(in: range, | |
with: "\n• ") | |
textView.text = newString | |
textView.sizeToFit() | |
tableView.beginUpdates() | |
tableView.endUpdates() | |
return false | |
} else { | |
let char = text.cString(using: String.Encoding.utf8)! | |
let isBackSpace = strcmp(char, "\\b") == -92 | |
if isBackSpace { | |
if textView.text == "• " { | |
textView.sizeToFit() | |
tableView.beginUpdates() | |
tableView.endUpdates() | |
return false | |
} | |
} | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment