Q:

How to calculate UITextView first baseline position relatively to the origin

How can I calculate UITextView first baseline position?

I tried calculating it this way:
self.textView.font!.descender + self.textView.font!.leading

However, the value I'm getting is not correct. Any ideas, hints?

A:

There is a diagram from the Apple document

From my understanding, font.descender + font.leading gives the distance between the first baseline and starting of the second line.
I would imagine font.lineHeight would give you the right number, if UITextField doesn't have a secret padding.

EDIT
UITextField and UITextView shared same UIFont property.
For UITextView, there's an extra textContainerInset can be set.
EDIT 2
A further look at the UITextView gives more clue about what can be achieved:
It actually has a textContainer property, which is a NSTextContainer.

The NSTextContainer class defines a region in which text is laid out. An NSLayoutManager object uses one or more NSTextContainer objects to determine where to break lines, lay out portions of text, and so on. 

And it's been used by layoutManager, theoretically the padding to the top of  first line of text could be found by usedRectForTextContainer(_:).
I will need to test this once I have a Mac in hand. :)

