0

insertTextPlaceholder is available as of ios 13

I am trying to create a place holder for textview

 if #available(iOS 13.0, *) {
        msgBox.insertTextPlaceholder(with: CGSize(width: 210, height: 40))
    }

I don't see any placeholder created after this code

How can I use it properly?

Utku Dalmaz
  • 9,780
  • 28
  • 90
  • 130

1 Answers1

0

First of all, I think you should not use it right now. Because the documentation are very poor. And UITextPlaceholder also has no interesting information.

I have not found anything useful about the function. Maybe it is not ready yet.

You should use Placeholder in UITextView.

What does the function do?

I found that it creates an empty space at the beginning of the UITextView with size that you pass to it.

1) UITextField (white field) without using insertTextPlaceholder: enter image description here

2) UITextField with using insertTextPlaceholder: enter image description here

Warning

It causes crashes. For example, if you add this:

let placeholder = textView.insertTextPlaceholder(with: CGSize(width: 100, height: 40))
textView.insertText("Test")

And type something in UITextView, you get this:

2020-04-29 14:20:10.264832+0300 StackOverflow[17081:284345] * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSBigMutableString substringWithRange:]: Range {1, 18446744073709551615} out of bounds; string length 5' *** First throw call stack: (...

Vladislav Markov
  • 587
  • 1
  • 5
  • 19