FS.O5 FS.O5 - 3 months ago 16
Objective-C Question

Calculate where text starts on centre alignment

I have a

UILabel
that I want to add a
UIView
exactly where the text starts.

The problem is that the text in the label is aligned to the centre so I don't know how to determinate where the actual text starts and where to position this
UIView
.

Any idea how can I calculate this thing?

Thank you!

Answer

You could also use

yourLabel.sizeToFit()

to automatically resize your label for the space it needs. And then read out the frame of your label with:

yourLabel.frame.size (width or height)
Comments