Click Ahead
Click Ahead

Reputation: 2852

Custom UITextView Placeholder Alignment on iOS7

I've created a custom UITextView in order to show a Placeholder. The method I used was drawInRect on the TextChangedNotification. It mostly works fine and a Placeholder is displayed.

The problem is that the Placeholder is positioned to the top left of the UITextView. What I would like is to position it after the cursor.

The only solution I have found so far is to set the X and Y coordinates for the CGRect passed into drawInRect to pad the content i.e.

CGRectMake(6,Font.PointSize/2,Width,Height) // X value is hardcoded

This seems like a bit of a hack.

Is there a better way position the placeholder text after the cursor ?

enter image description here

Upvotes: 2

Views: 576

Answers (1)

Daniele
Daniele

Reputation: 2469

You should be able to retrieve the caret rect with this one

CGRect caretRect = [textView caretRectForPosition:textView.beginningOfDocument];

Upvotes: 3

Related Questions