Skip to content

Instantly share code, notes, and snippets.

@DisappearPing
Created August 14, 2023 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DisappearPing/1bf02032b171df81ccca108559dccf2b to your computer and use it in GitHub Desktop.
Save DisappearPing/1bf02032b171df81ccca108559dccf2b to your computer and use it in GitHub Desktop.
強置換行加點
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