代码之家  ›  专栏  ›  技术社区  ›  Adam

Swift iOS文本区域我可以从偏移或光标中删除文本吗

  •  0
  • Adam  · 技术社区  · 6 年前
    var currenTextCount = 0
    func textViewDidChange(_ textView: UITextView) {
        currentTextCount = currentTextCount+1
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    
    
        let startPosition: UITextPosition = writeArea.beginningOfDocument
    
        let selectedRange: UITextRange = writeArea.selectedTextRange!
    
        let cursorPosition = writeArea.offset(from: startPosition, to: selectedRange.start)
    
        i don't know
    }
    

    删除左右空格之间的文本

    1 回复  |  直到 6 年前
        1
  •  0
  •   Adam    6 年前
      let newPosition:UITextPosition! = writeArea.position(from: selectedRange.start, offset: -currenTextCount)
      let nowPosition:UITextPosition! = writeArea.position(from: selectedRange.start, offset: 0)
      let tagRange:UITextRange! = writeArea.textRange(from: newPosition, to: nowPosition)
            writeArea.replace(tagRange, withText: selectedTag)
      writeArea.replace(tagRagne, withText: "String")