4

I have an app that have user feedback feature. I have done the view as shown in the image. Feedback view that I made

  • Message area is using UITextView.

What I want to do now is when user finished editing the textView, then they click other places such as the star rating or any area besides textview, it will hide the cursor on the textview but it will keep the written text at the same time.

Can anyone help me with this? Thank you.

Syafiq Mastor
  • 178
  • 2
  • 10
  • Using gesture you can do this : http://stackoverflow.com/questions/5306240/iphone-dismiss-keyboard-when-touching-outside-of-uitextfield – Pushpa Y Dec 08 '15 at 08:55
  • 1
    Possible duplicate of [UITextview Hide cursor/Change color of cursor](http://stackoverflow.com/questions/11525255/uitextview-hide-cursor-change-color-of-cursor) – Rashwan L Dec 08 '15 at 20:42

3 Answers3

19

You can make the tint color transparent to hide the cursor.

textView.tintColor = UIColor.clearColor()

In Swift 3:

textView.tintColor = UIColor.clear
Adam
  • 26,549
  • 8
  • 62
  • 79
5

Update for Swift 3.x:

textField.tintColor = .clear
Rolf ツ
  • 8,611
  • 6
  • 47
  • 72
David Sanford
  • 735
  • 12
  • 26
1

Try this:

1) Add a tap gesture recogniser to your view in an appropriate place (viewDidLoad for example)

  let tapRecognizer = UITapGestureRecognizer(target: self, action: "hideKeyboard")
  view.addGestureRecognizer(tapRecognizer)

2) Then you need to add hideKeyboard method. Example implementation

func hideKeyboard() {
  view.endEditing(true)
}

That should do it :)

66o
  • 756
  • 5
  • 10