LoginSignup
1
3

More than 5 years have passed since last update.

TextViewの選択中の文字列を取得する方法

Posted at

on.gif


func textViewDidChangeSelection(_ textView: UITextView) {

        let location = textView.selectedRange.location
        let length = textView.selectedRange.length
        let text = (textView.text as NSString).substring(with: NSRange(location:location,length: length))
        print(location)
        print(length)
        print(text)

    }

参照

【swift】uitextviewの選択範囲の文字列を取得する方法
How to restrict cursor position in swift?

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3