Advertisement
Guest User

Untitled

a guest
Jul 11th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.14 KB | None | 0 0
  1.     func changeText(_ range: NSRange, replacementText text: NSString) {
  2.         if validInputStarted {
  3.             if stringRange.location >= range.location && stringRange.location < range.location + range.length {
  4.                 validInputStarted = false
  5.             } else if range.location < stringRange.location {
  6.                 stringRange.location -= range.length - text.length
  7.             } else if range.location > stringRange.location && range.location <= stringRange.location + stringRange.length {
  8.                 stringRange.length -= stringRange.length - (range.location - stringRange.location) - text.length
  9.             }
  10.            
  11.             var str = "";
  12.             if stringRange.location + 1 < (textView.text as NSString).length {
  13.                 str = (textView.text! as NSString).substring(with: NSRange(location: stringRange.location + 1, length: stringRange.length - 1))
  14.             }
  15.         }
  16.         if text.length > 0 && (text as NSString).substring(to: 1) == "@" {
  17.             validInputStarted = true
  18.             stringRange.location = range.location
  19.             stringRange.length = text.length
  20.         }
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement