SHARE
TWEET

Untitled

a guest Nov 15th, 2017 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///取得TextField文案的開始點
  2.       let beginning = self.textField.beginningOfDocument
  3.       ///新的起始點為文案的開始點往後0位
  4.       let newStartPosition = self.textField.position(from: beginning, offset: 0)
  5.       ///新的結束點為文案開始點後往後3位
  6.       let newEndPosition = self.textField.position(from: beginning, offset: 3)
  7.       ///要確定新的點都是存在的才可以設定
  8.       if let newStartPosition = newStartPosition,
  9.           let newEndPosition = newEndPosition{
  10.           ///創建新的文字選擇區域
  11.           let newSelectionRange = self.textField.textRange(from: newStartPosition, to:newEndPosition)
  12.           ///指定新的文字選擇區域
  13.           self.textField.selectedTextRange = newSelectionRange
  14.       }
RAW Paste Data
Top