Placeholder in UITextView

前端 未结 30 3068
野趣味
野趣味 2020-11-22 16:01

My application uses an UITextView. Now I want the UITextView to have a placeholder similar to the one you can set for an UITextField.<

30条回答
  •  自闭症患者
    2020-11-22 16:20

    What you can do is set up the text view with some initial value in the text property, and change the textColor to [UIColor grayColor] or something similar. Then, whenever the text view becomes editable, clear the text and present a cursor, and if the text field is ever empty again, put your placeholder text back. Change the color to [UIColor blackColor] as appropriate.

    It's not exactly the same as the placeholder functionality in a UITextField, but it's close.

提交回复
热议问题