Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Swift, how to get the y position of a text baseline of a UILabel?

I'm trying to get the exactly baseline of a text of a UILabel.

label.frame.maxY returns the max y of the box of the UILabel.

But what I really want is the maxY of the position of the text.

Ignore the "button". I just searched this image from google. I know how to get what the first returns (maxY), but I want to know how to get the second one (where the dashline is under the text).

enter image description here

Thanks for any help!

like image 633
Roberto Sampaio Avatar asked Feb 01 '17 14:02

Roberto Sampaio


1 Answers

You can achieve this quite simply :

let baselineY = label.frame.origin.y + label.font.ascender;
like image 145
Losiowaty Avatar answered Nov 08 '22 20:11

Losiowaty